fix: reserved keywords as col name (#25718)

This commit is contained in:
Ankush Menat 2024-03-29 15:43:33 +05:30 committed by GitHub
parent 34f1b9cb65
commit 87ffe25e71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 3 deletions

View file

@ -338,7 +338,7 @@ def check_if_doc_is_dynamically_linked(doc, method="Delete"):
df["table"] = ", `parent`, `parenttype`, `idx`" if meta.istable else ""
for refdoc in frappe.db.sql(
"""select `name`, `docstatus` {table} from `tab{parent}` where
{options}=%s and {fieldname}=%s""".format(**df),
`{options}`=%s and `{fieldname}`=%s""".format(**df),
(doc.doctype, doc.name),
as_dict=True,
):

View file

@ -202,9 +202,11 @@ class Document(BaseDocument):
if hasattr(self, "__setup__"):
self.__setup__()
return self
def reload(self):
"""Reload document from database"""
self.load_from_db()
return self.load_from_db()
def get_latest(self):
if not getattr(self, "_doc_before_save", None):

View file

@ -43,7 +43,7 @@ def get_dynamic_link_map(for_delete=False):
else:
try:
links = frappe.db.sql_list(
"""select distinct {options} from `tab{parent}`""".format(**df)
"""select distinct `{options}` from `tab{parent}`""".format(**df)
)
for doctype in links:
dynamic_link_map.setdefault(doctype, []).append(df)

View file

@ -1,5 +1,9 @@
import random
import string
import frappe
from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.database import savepoint
from frappe.desk.form import linked_with
from frappe.tests.utils import FrappeTestCase
@ -148,3 +152,36 @@ class TestLinkedWith(FrappeTestCase):
amendment.submit()
self.assertRaises(frappe.LinkExistsError, doc.delete)
def test_reserved_keywords(self):
dt_name = "Test " + "".join(random.sample(string.ascii_lowercase, 10))
new_doctype(
dt_name,
fields=[
{
"fieldname": "from",
"fieldtype": "Link",
"options": "DocType",
},
{
"fieldname": "order",
"fieldtype": "Dynamic Link",
"options": "from",
},
],
is_submittable=True,
).insert()
linked_doc = frappe.new_doc(dt_name).insert().submit()
second_doc = (
frappe.new_doc(dt_name, **{"from": linked_doc.doctype, "order": linked_doc.name})
.insert()
.submit()
)
with savepoint(frappe.LinkExistsError):
linked_doc.cancel() and self.fail("Cancellation shouldn't have worked")
second_doc.cancel()
linked_doc.reload().cancel()