Opened 5 years ago

Closed 15 months ago

#12531 closed Bug (duplicate)

Model field name 'hiding' should not be permitted when field is defined in one of the parent models

Reported by: parxier Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Normal Keywords:
Cc: bas@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to http://docs.djangoproject.com/en/1.1/topics/db/models/#field-name-hiding-is-not-permitted it is not permitted to hide field name in child
model and django would raise a FieldError exception. And that's
exactly what happens:

class Phone(models.Model):
  pass

class Service(models.Model):
   phone = models.ForeignKey(Phone, related_name='services')

class Call(Service):
   phone = models.ForeignKey(Phone, related_name='calls')
> manage.py validate
django.core.exceptions.FieldError: Local field 'phone' in class 'Call' clashes with field of similar name from base class 'Service'

works as expected... no problem

However, if I add new IntermediateService model like this:

class Phone(models.Model):
  pass

class Service(models.Model):
   phone = models.ForeignKey(Phone, related_name='services')

class IntermediateService(Service):
   class Meta:
       abstract = True

class Call(IntermediateService):
   phone = models.ForeignKey(Phone, related_name='calls')

...surprisingly it validates:

> manage.py validate
0 errors found

and generates sqls for postgresql:

> manage.py sql app

CREATE TABLE "app_phone" (
   "id" serial NOT NULL PRIMARY KEY
);
CREATE TABLE "app_service" (
   "id" serial NOT NULL PRIMARY KEY,
   "phone_id" integer NOT NULL REFERENCES "app_phone" ("id")
DEFERRABLE INITIALLY DEFERRED
);
CREATE TABLE "app_call" (
   "service_ptr_id" integer NOT NULL UNIQUE REFERENCES
"app_service" ("id") DEFERRABLE INITIALLY DEFERRED,
   "phone_id" integer NOT NULL REFERENCES "app_phone" ("id")
DEFERRABLE INITIALLY DEFERRED
);

Looks like a bug to me.

Change History (6)

comment:1 Changed 5 years ago by parxier

  • Cc bas@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

I'm not completely convinced that the error isn't using an abstract model in the middle of an inheritance chain. However, either way, there is a bug than needs to be resolved.

comment:3 Changed 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 15 months ago by timo

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

Duplicate of #17673

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