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:
Prathamesh Kurunkar 2026-02-16 20:28:38 +05:30 committed by GitHub
parent 91a41c921a
commit 69e655d08b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -634,6 +634,9 @@ class Database:
from frappe.model.utils import is_single_doctype
out = None
if isinstance(fieldname, list):
fieldname = tuple(fieldname)
if cache and isinstance(filters, str) and fieldname in self.value_cache[doctype][filters]:
return self.value_cache[doctype][filters][fieldname]

View file

@ -138,6 +138,14 @@ class TestDB(IntegrationTestCase):
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):
frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode())