#42665·frappe

fix: remove auto-added unique when field autoname is removed

Author: Mohanapriya-selvarajCreated Sep 9, 2026Updated Sep 18, 2026
Labelsbug

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

  1. Create a new DocType.
  2. Add a Data field named student_name.
  3. Set the naming rule to By fieldname.
  4. Select student_name as the naming field.
  5. Save the DocType.
  6. Confirm that student_name becomes Unique.
  7. Change the naming rule to another method such as hash.
  8. Save the DocType again.
  9. Check the student_name field.

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_namefield:student_id

should result in:

  • student_name → Unique = No
  • student_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.