1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #26784 -- Made ForeignKey.validate() pass model to router if model_instance=None.

This commit is contained in:
Ben Demboski
2016-06-20 14:52:14 -07:00
committed by Tim Graham
parent 03f6d272ab
commit 2224a56631
2 changed files with 12 additions and 1 deletions

View File

@@ -586,6 +586,17 @@ class QueryTestCase(TestCase):
pluto = Pet.objects.using('other').create(name="Pluto", owner=mickey)
self.assertIsNone(pluto.full_clean())
# Any router that accesses `model` in db_for_read() works here.
@override_settings(DATABASE_ROUTERS=[AuthRouter()])
def test_foreign_key_validation_with_router(self):
"""
ForeignKey.validate() passes `model` to db_for_read() even if
model_instance=None.
"""
mickey = Person.objects.create(name="Mickey")
owner_field = Pet._meta.get_field('owner')
self.assertEqual(owner_field.clean(mickey.pk, None), mickey.pk)
def test_o2o_separation(self):
"OneToOne fields are constrained to a single database"
# Create a user and profile on the default database