refactor!: frappe.db.get_singles_dict
* Cast single's values as their fieldtypes before returning * Support previously dead debug parameter * Consider single with no meta as non-existent; skip query Decided to go ahead with the breaking change given the nature of the existing usages of get_singles_dict :crie:
This commit is contained in:
parent
e681233e98
commit
f74dc5023d
1 changed files with 19 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
# Database Module
|
||||
|
|
@ -18,6 +18,7 @@ import frappe
|
|||
import frappe.defaults
|
||||
import frappe.model.meta
|
||||
from frappe import _
|
||||
from frappe.exceptions import DoesNotExistError
|
||||
from frappe.model.utils.link_count import flush_local_link_count
|
||||
from frappe.query_builder.functions import Count
|
||||
from frappe.query_builder.utils import DocType
|
||||
|
|
@ -628,14 +629,28 @@ class Database(object):
|
|||
# Get coulmn and value of the single doctype Accounts Settings
|
||||
account_settings = frappe.db.get_singles_dict("Accounts Settings")
|
||||
"""
|
||||
result = self.query.get_sql(
|
||||
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},
|
||||
fields=["field", "value"],
|
||||
for_update=for_update,
|
||||
).run()
|
||||
).run(debug=debug)
|
||||
|
||||
return frappe._dict(result)
|
||||
for fieldname, value in queried_result:
|
||||
if df := meta.get_field(fieldname):
|
||||
casted_value = cast(df.fieldtype, value)
|
||||
else:
|
||||
casted_value = value
|
||||
return_value[fieldname] = casted_value
|
||||
|
||||
return return_value
|
||||
|
||||
@staticmethod
|
||||
def get_all(*args, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue