Author: ramiro Date: 2010-11-16 16:09:13 -0600 (Tue, 16 Nov 2010) New Revision: 14580
Modified: django/trunk/django/db/models/fields/related.py django/trunk/tests/regressiontests/multiple_database/tests.py Log: Fixed #14691 -- Made ForeignKey.validate() use the right database. Thanks Marco Paolini for the report. Modified: django/trunk/django/db/models/fields/related.py =================================================================== --- django/trunk/django/db/models/fields/related.py 2010-11-16 21:34:53 UTC (rev 14579) +++ django/trunk/django/db/models/fields/related.py 2010-11-16 22:09:13 UTC (rev 14580) @@ -835,7 +835,10 @@ if value is None: return - qs = self.rel.to._default_manager.filter(**{self.rel.field_name:value}) + using = router.db_for_read(model_instance.__class__, instance=model_instance) + qs = self.rel.to._default_manager.using(using).filter( + **{self.rel.field_name: value} + ) qs = qs.complex_filter(self.rel.limit_choices_to) if not qs.exists(): raise exceptions.ValidationError(self.error_messages['invalid'] % { Modified: django/trunk/tests/regressiontests/multiple_database/tests.py =================================================================== --- django/trunk/tests/regressiontests/multiple_database/tests.py 2010-11-16 21:34:53 UTC (rev 14579) +++ django/trunk/tests/regressiontests/multiple_database/tests.py 2010-11-16 22:09:13 UTC (rev 14580) @@ -581,6 +581,12 @@ self.assertEquals(Person.objects.using('other').count(), 0) self.assertEquals(Pet.objects.using('other').count(), 0) + def test_foreign_key_validation(self): + "ForeignKey.validate() uses the correct database" + mickey = Person.objects.using('other').create(name="Mickey") + pluto = Pet.objects.using('other').create(name="Pluto", owner=mickey) + self.assertEquals(None, pluto.full_clean()) + def test_o2o_separation(self): "OneToOne fields are constrained to a single database" # Create a user and profile on the default database -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.