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.
* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26784#comment:1>
Comment (by bendemboski):
Patch is:
[https://github.com/django/django/pull/6813]
--
Ticket URL: <https://code.djangoproject.com/ticket/26784#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26784#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26784#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"2224a56631eae3342993e4b7b90e80f59a167151" 2224a566]:
{{{
#!CommitTicketReference repository=""
revision="2224a56631eae3342993e4b7b90e80f59a167151"
Fixed #26784 -- Made ForeignKey.validate() pass `model` to router if
model_instance=None.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26784#comment:5>