diff --git a/frappe/database/database.py b/frappe/database/database.py index 39ca846904..44256f58b0 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -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)