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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user