Opened 5 years ago

Closed 17 months ago

Last modified 17 months ago

#16739 closed Bug (duplicate)

Model field clash not detected beyond parent

Reported by: Leo Owned by:
Component: Core (System checks) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When a local field in a class has the same name as a field in the superclass Django throws a FieldError when it spins up. However, it only checks the immediate parent, it doesn't go further up the tree so the following code doesn't trigger a FieldError (which it should):

class A(models.Model):
    foo = models.IntegerField()

class B(A):

class C(B):
    foo = models.IntegerField()

Attachments (1)

16739-test.diff (748 bytes) - added by timgraham 21 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by aaugustin

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

I confirm the bug. With this code in a

class GrandParent(models.Model):
    number = models.IntegerField()

class Parent(GrandParent):

class Child(Parent):
    number = models.IntegerField()

Expected result of ./ validate:

FieldError: Local field 'number' in class 'Child' clashes with field of similar name from base class 'GrandParent'

Actual result: no error.

I tried to write a test case in invalid_models, but that didn't work because the name clash creates an exception, not a validation error.

comment:2 Changed 4 years ago by swcisel

  • Owner changed from nobody to swcisel
  • Status changed from new to assigned

comment:3 Changed 4 years ago by akaariai

  • Type changed from Uncategorized to Bug

comment:4 Changed 21 months ago by timgraham

  • Component changed from Database layer (models, ORM) to Core (System checks)
  • Owner swcisel deleted
  • Status changed from assigned to new
  • Summary changed from field clash not detected beyond parent to Model field clash not detected beyond parent

Confirmed this is still an issue with the attached test for Django's test suite.

Changed 21 months ago by timgraham

comment:5 Changed 17 months ago by karlwnw

I think this ticket can be marked as fixed or duplicate now, fixed here #24249.

comment:6 Changed 17 months ago by claudep

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

Right, thanks for checking (Tim's test is now passing well).

comment:7 Changed 17 months ago by Leo

Thanks guys! Great to have this cleaned up!

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