fix: Don't assume homogeneous data in meta tables

Steps to reproduce:
- enable developer mode (doesn't happen in prod)
- Save a document with set only once fields
- Reload the page (requests meta again which is now polluted)

This is new category of bug surfaced because meta objects now live
longer than request and all kinds of weird `self._cached_property`
starts getting serialized.

Co-Authored-By: ruthra kumar <ruthra@erpnext.com>
This commit is contained in:
Ankush Menat 2025-01-16 17:03:42 +05:30
parent 9a1eab7512
commit b3859d9fa3
2 changed files with 10 additions and 0 deletions

View file

@ -796,6 +796,14 @@ class TestDocType(IntegrationTestCase):
)
self.assertRaises(frappe.ValidationError, recursive_dt.insert)
def test_meta_serialization(self):
doctype = new_doctype(
fields=[{"fieldname": "some_fieldname", "fieldtype": "Data", "set_only_once": 1}]
).insert()
doc = frappe.new_doc(doctype.name, some_fieldname="something").insert()
doc.save()
frappe.get_meta(doctype.name).as_dict()
def new_doctype(
name: str | None = None,

View file

@ -188,6 +188,8 @@ class Meta(Document):
def as_dict(self, no_nulls=False):
def serialize(doc):
if isinstance(doc, dict):
return doc.copy()
out = {}
for key, value in doc.__dict__.items():
if isinstance(value, list | tuple):