fix(db): support list of fields in get_value method when cache is True (#37050)
* fix(db): support list of fields in get_value method when cache is True * test(db): ensure cache hit does not execute db query
This commit is contained in:
parent
91a41c921a
commit
69e655d08b
2 changed files with 11 additions and 0 deletions
|
|
@ -634,6 +634,9 @@ class Database:
|
||||||
from frappe.model.utils import is_single_doctype
|
from frappe.model.utils import is_single_doctype
|
||||||
|
|
||||||
out = None
|
out = None
|
||||||
|
if isinstance(fieldname, list):
|
||||||
|
fieldname = tuple(fieldname)
|
||||||
|
|
||||||
if cache and isinstance(filters, str) and fieldname in self.value_cache[doctype][filters]:
|
if cache and isinstance(filters, str) and fieldname in self.value_cache[doctype][filters]:
|
||||||
return self.value_cache[doctype][filters][fieldname]
|
return self.value_cache[doctype][filters][fieldname]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,14 @@ class TestDB(IntegrationTestCase):
|
||||||
frappe.db.get_value("DocType", "DocField", order_by="creation desc, modified asc, name", run=0),
|
frappe.db.get_value("DocType", "DocField", order_by="creation desc, modified asc, name", run=0),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test with list of fields and cache=True
|
||||||
|
result = frappe.db.get_value("User", "Administrator", ["name", "email"], cache=True)
|
||||||
|
self.assertEqual(result, ("Administrator", "admin@example.com"))
|
||||||
|
# Verify cache hit - second call should not execute any queries
|
||||||
|
with self.assertQueryCount(0):
|
||||||
|
cached_result = frappe.db.get_value("User", "Administrator", ["name", "email"], cache=True)
|
||||||
|
self.assertEqual(result, cached_result)
|
||||||
|
|
||||||
def test_escape(self):
|
def test_escape(self):
|
||||||
frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode())
|
frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue