Opened 8 years ago
Closed 8 years ago
#26784 closed Bug (fixed)
foreign key validate() violates router API when no instance specified
Reported by: | Ben Demboski | Owned by: | Ben Demboski |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | 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
to reproduce:
- configure two databases:
default
andother
- have two models Person and Pet:
class Person(models.Model): name = models.CharField(max_length=100) class Pet(models.Model): name = models.CharField(max_length=100) owner = models.ForeignKey(Person)
- have a database router enabled that routes models in the app containing
person
andpet
(let's say its calledpetstore
) to theother
database:class PetStoreRouter(object): def db_for_read(self, model, **hints): if model._meta.app_label == 'petstore': return 'other' return None def db_for_write(self, model, **hints): if model._meta.app_label == 'petstore': return 'other' return None
- create a Person instance named
person
- call
clean()
on thePet
model'sowner
field passing inperson
s pk, but no model:Pet._meta.get_field('owner').clean(person.pk, None)
The result will be a exception thrown from inside the router's db_for_read()
method:
AttributeError: type object 'NoneType' has no attribute '_meta'
because the model
argument contains <type 'NoneType'>
(which doesn't have a _meta
attribute) instead of a model class.
Change History (5)
comment:1 by , 8 years ago
Status: | new → assigned |
---|
comment:2 by , 8 years ago
comment:3 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Patch is:
https://github.com/django/django/pull/6813