#26784: foreign key validate() violates router API when no instance specified
----------------------------------------------+-------------------------
Reporter: bendemboski | Owner: bendemboski
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+-------------------------
to reproduce:
1. configure two databases: `default` and `other`
1. 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)
}}}
1. have a database router enabled that routes models in the app
containing `person` and `pet` (let's say its called `petstore`) to the
`other` 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
}}}
1. create a Person instance named `person`
1. call `clean()` on the `Pet` model's `owner` field passing in `person`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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26784>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.59e21373ce20288bf1e22d7af452170c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.