refactor!: frappe.db.get_singles_dict
* Don't cast values by default - only if cast kwarg is set
* Reverts breaking behaviour added via f74dc5023d
This commit is contained in:
parent
562499609c
commit
bbc90e6578
1 changed files with 14 additions and 8 deletions
|
|
@ -619,23 +619,19 @@ class Database(object):
|
|||
else:
|
||||
return r and [[i[1] for i in r]] or []
|
||||
|
||||
def get_singles_dict(self, doctype, debug=False, *, for_update=False):
|
||||
def get_singles_dict(self, doctype, debug=False, *, for_update=False, cast=False):
|
||||
"""Get Single DocType as dict.
|
||||
|
||||
:param doctype: DocType of the single object whose value is requested
|
||||
:param debug: Execute query in debug mode - print to STDOUT
|
||||
:param for_update: Take `FOR UPDATE` lock on the records
|
||||
:param cast: Cast values to Python data types based on field type
|
||||
|
||||
Example:
|
||||
|
||||
# Get coulmn and value of the single doctype Accounts Settings
|
||||
account_settings = frappe.db.get_singles_dict("Accounts Settings")
|
||||
"""
|
||||
return_value = frappe._dict()
|
||||
|
||||
try:
|
||||
meta = frappe.get_meta(doctype)
|
||||
except DoesNotExistError:
|
||||
return return_value
|
||||
|
||||
queried_result = self.query.get_sql(
|
||||
"Singles",
|
||||
filters={"doctype": doctype},
|
||||
|
|
@ -643,6 +639,16 @@ class Database(object):
|
|||
for_update=for_update,
|
||||
).run(debug=debug)
|
||||
|
||||
if not cast:
|
||||
return frappe._dict(queried_result)
|
||||
|
||||
try:
|
||||
meta = frappe.get_meta(doctype)
|
||||
except DoesNotExistError:
|
||||
return frappe._dict(queried_result)
|
||||
|
||||
return_value = frappe._dict()
|
||||
|
||||
for fieldname, value in queried_result:
|
||||
if df := meta.get_field(fieldname):
|
||||
casted_value = cast(df.fieldtype, value)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue