﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26784	foreign key validate() violates router API when no instance specified	Ben Demboski	Ben Demboski	"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."	Bug	closed	Database layer (models, ORM)	1.9	Normal	fixed			Ready for checkin	1	0	0	0	0	0
