Opened 13 years ago

Closed 10 years ago

Last modified 10 years ago

#16739 closed Bug (duplicate)

Model field clash not detected beyond parent

Reported by: Leo Shklovskii Owned by:
Component: Core (System checks) Version: dev
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

Description

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):
    pass

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

Attachments (1)

16739-test.diff (748 bytes ) - added by Tim Graham 10 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

I confirm the bug. With this code in a models.py:

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

class Parent(GrandParent):
    pass

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

Expected result of ./manage.py 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 by swcisel, 12 years ago

Owner: changed from nobody to swcisel
Status: newassigned

comment:3 by Anssi Kääriäinen, 12 years ago

Type: UncategorizedBug

comment:4 by Tim Graham, 10 years ago

Component: Database layer (models, ORM)Core (System checks)
Owner: swcisel removed
Status: assignednew
Summary: field clash not detected beyond parentModel field clash not detected beyond parent

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

by Tim Graham, 10 years ago

Attachment: 16739-test.diff added

comment:5 by Karl, 10 years ago

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

comment:6 by Claude Paroz, 10 years ago

Resolution: duplicate
Status: newclosed

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

comment:7 by Leo Shklovskii, 10 years ago

Thanks guys! Great to have this cleaned up!

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