Opened 10 days ago

Last modified 5 days ago

#35551 closed Bug

Unique checks skipped when changing primary key — at Version 1

Reported by: Csirmaz Bendegúz Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Csirmaz Bendegúz)

I noticed the unique checks are skipped (_perform_unique_checks) when an object's primary key is changed.

Given:

# models.py
class Dummy(models.Model):
    id = models.IntegerField(primary_key=True)

# admin.py
admin.site.register(Dummy)
  1. Create Dummy (1), Dummy (2).
  2. Change Dummy (2)'s Id field -> 1
  3. No error, unique checks skipped
  4. Change Dummy (1)'s Id field -> 3
  5. A new Dummy (1) is created (why?)

I believe step 5 should never happen, since step 3 should fail with a unique check error.

Change History (1)

comment:1 by Csirmaz Bendegúz, 10 days ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top