fix: added 'autoname' to reserved keywords (#35473)

* fix: added 'autoname' to reserved keywords

* fix: prevent using autoname as DocField name

- Add validation for autoname in check_invalid_fieldnames()
- Treat Python keywords as reserved fieldnames

* fix: move autoname out of reserved keywords

* fix: move python keywords out of reserved keywords

* fix: skip reserved docfield name check for 'DocType'

---------

Co-authored-by: Raiza Safeel <raizasafeel@Raizas-MacBook-Air.local>
This commit is contained in:
Raizaaa 2025-12-31 12:00:49 +05:30 committed by GitHub
parent e8a5529b98
commit 0a2ab6364c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -1278,6 +1278,8 @@ def validate_fields(meta: Meta):
validate_column_name(fieldname)
def check_invalid_fieldnames(docname, fieldname):
RESERVED_DOCFIELD_NAMES = frozenset(("autoname",))
if fieldname in RESERVED_KEYWORDS:
frappe.throw(
_("{0}: fieldname cannot be set to reserved keyword {1}").format(
@ -1287,6 +1289,15 @@ def validate_fields(meta: Meta):
title=_("Invalid Fieldname"),
)
if fieldname in RESERVED_DOCFIELD_NAMES and docname != "DocType":
frappe.throw(
_("{0}: fieldname cannot be set to reserved field {1} in DocType").format(
frappe.bold(docname),
frappe.bold(fieldname),
),
title=_("Invalid Fieldname"),
)
def check_unique_fieldname(docname, fieldname):
duplicates = list(
filter(None, map(lambda df: (df.fieldname == fieldname and str(df.idx)) or None, fields))

View file

@ -2,6 +2,7 @@
# License: MIT. See LICENSE
import datetime
import json
import keyword
import weakref
from types import MappingProxyType
from typing import TYPE_CHECKING, TypeVar