Opened 4 years ago

Closed 6 months ago

Last modified 6 months ago

#15321 closed Bug (fixed)

Models._get_unique_checks() does not return grandparents' unique checks

Reported by: jku Owned by: aron45
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: models, unique checks
Cc: aron45 Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following models:

class Project(models.Model):
    title = models.CharField(max_length=255)
    internal_id = models.CharField(max_length=255, unique=True)

class SubProject(Project):
    # ... fields of SubProject ...
    pass

class SubSubProject(SubProject):
    # ... fields of SubSubProject ...
    pass

Following code works as expected (b.full_clean() throws a ValidationError):

a = SubProject( title = 'A', internal_id = 1 )
a.save()
b = SubProject( title = 'B', internal_id = 1 )
b.full_clean() # Throws ValidationError

Following code does not work as expected (b.full_clean() does not throw an exception, b.save() throws an IntegrityError):

a = SubSubProject( title = 'A', internal_id = 2 )
a.save()
b = SubSubProject( title = 'B', internal_id = 2 )
b.full_clean() # Does not throw any exception!
b.save() # Throws IntegrityError, of course!

Attachments (2)

sub_sub_unique_fix (4.1 KB) - added by sswang 4 years ago.
fix for sub sub inheritance uniqueness
sub_sub_unique_fix.patch (4.1 KB) - added by sswang 4 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by sswang

fix for sub sub inheritance uniqueness

comment:2 Changed 4 years ago by sswang

  • Owner changed from nobody to sswang

comment:3 Changed 4 years ago by sswang

  • Status changed from new to assigned

Changed 4 years ago by sswang

comment:4 Changed 4 years ago by sswang

  • Has patch set

comment:5 Changed 4 years ago by sswang

still needs fix for unique_togethers

comment:6 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:7 Changed 3 years ago by lrekucki

  • Easy pickings unset
  • Patch needs improvement set
  • UI/UX unset

comment:8 Changed 6 months ago by aron45

  • Owner changed from sswang to aron45

comment:9 Changed 6 months ago by aron45

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:10 Changed 6 months ago by jarshwah

  • Patch needs improvement unset
  • Resolution fixed deleted
  • Status changed from closed to new

I presume you didn't mean to close this case off, since you've linked a pull request.

comment:11 Changed 6 months ago by charettes

  • Needs tests set
  • Patch needs improvement set
  • Version changed from 1.2 to master

comment:12 Changed 6 months ago by aron45

  • Cc aron45 added

comment:13 Changed 6 months ago by aron45

I updated the pull request

comment:14 Changed 6 months ago by timgraham

  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:15 Changed 6 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 79f27f2b61aeac763ae048416ef8a97c2b639ae8:

Fixed #15321 -- Honored ancestors unique checks.

Thanks to Tim for the review.

comment:16 Changed 6 months ago by Simon Charette <charette.s@…>

In fc49e736484892eaa516826d93660c7ab53a6c3e:

[1.8.x] Fixed #15321 -- Honored ancestors unique checks.

Thanks to Tim for the review.

Backport of 79f27f2b61aeac763ae048416ef8a97c2b639ae8 from master

Note: See TracTickets for help on using tickets.
Back to Top