Fixed #20337 -- Clarified error message when database relation is not allowed.

This commit is contained in:
Dan Loewenherz 2013-04-30 13:28:09 -07:00 committed by Tim Graham
parent 127d9b2792
commit 07a73a2714
1 changed files with 2 additions and 4 deletions

View File

@ -228,8 +228,7 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri
value._state.db = router.db_for_write(value.__class__, instance=instance) value._state.db = router.db_for_write(value.__class__, instance=instance)
elif value._state.db is not None and instance._state.db is not None: elif value._state.db is not None and instance._state.db is not None:
if not router.allow_relation(value, instance): if not router.allow_relation(value, instance):
raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' % raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value)
(value, instance._state.db, value._state.db))
related_pk = tuple([getattr(instance, field.attname) for field in self.related.field.foreign_related_fields]) related_pk = tuple([getattr(instance, field.attname) for field in self.related.field.foreign_related_fields])
if None in related_pk: if None in related_pk:
@ -328,8 +327,7 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec
value._state.db = router.db_for_write(value.__class__, instance=instance) value._state.db = router.db_for_write(value.__class__, instance=instance)
elif value._state.db is not None and instance._state.db is not None: elif value._state.db is not None and instance._state.db is not None:
if not router.allow_relation(value, instance): if not router.allow_relation(value, instance):
raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' % raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value)
(value, instance._state.db, value._state.db))
# If we're setting the value of a OneToOneField to None, we need to clear # If we're setting the value of a OneToOneField to None, we need to clear
# out the cache on any old related object. Otherwise, deleting the # out the cache on any old related object. Otherwise, deleting the