fix: Don't run query if dn is None (#22475)

This commit is contained in:
Ankush Menat 2023-09-19 20:41:15 +05:30 committed by GitHub
parent be5e05f7a2
commit acd1b9d64e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -879,7 +879,9 @@ class Database:
"""
from frappe.model.utils import is_single_doctype
if (dn is None or dt == dn) and is_single_doctype(dt):
if dn is None or dt == dn:
if not is_single_doctype(dt):
return
deprecation_warning(
"Calling db.set_value on single doctype is deprecated. This behaviour will be removed in future. Use db.set_single_value instead."
)

View file

@ -693,6 +693,12 @@ class TestDBSetValue(FrappeTestCase):
current_value = frappe.db.get_single_value("System Settings", "deny_multiple_sessions")
self.assertEqual(current_value, changed_value)
def test_none_no_set_value(self):
frappe.db.set_value("User", None, "middle_name", "test")
with self.assertQueryCount(0):
frappe.db.set_value("User", None, "middle_name", "test")
frappe.db.set_value("User", "User", "middle_name", "test")
def test_update_single_row_single_column(self):
frappe.db.set_value("ToDo", self.todo1.name, "description", "test_set_value change 1")
updated_value = frappe.db.get_value("ToDo", self.todo1.name, "description")