fix: remove auto-added unique when field autoname is removed
Description
When a DocType uses field-based autonaming (field:<fieldname>), Frappe
automatically marks the selected field as Unique.
When the field-based autoname is later removed or changed to another naming method, the automatically added Unique property remains enabled.
Steps to reproduce
- Create a new DocType.
- Add a Data field named
student_name. - Set the naming rule to By fieldname.
- Select
student_nameas the naming field. - Save the DocType.
- Confirm that
student_namebecomes Unique. - Change the naming rule to another method such as
hash. - Save the DocType again.
- Check the
student_namefield.
Observed behavior
The student_name field remains Unique even though it is no longer used
for field-based autonaming.
Expected behavior
The Unique property automatically added for field-based autonaming should be removed when that field is no longer used for field-based autonaming.
A Unique property explicitly configured by the user should remain unchanged.
Additional case
Changing:
field:student_name → field:student_id
should result in:
student_name→ Unique = Nostudent_id→ Unique = Yes
Environment
- Frappe v16
Additional information
I reproduced this behavior locally.
I also found PR #42642 addressing similar behavior. This issue additionally requires distinguishing automatically generated Unique properties from manually configured Unique properties, so manually configured constraints are preserved.
Source: frappe/frappe