Skip to content

Commit

Permalink
Fixed #20337 -- Clarified error message when database relation is not…
Browse files Browse the repository at this point in the history
… allowed.
  • Loading branch information
dlo authored and timgraham committed Jun 1, 2013
1 parent 127d9b2 commit 07a73a2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions django/db/models/fields/related.py
Expand Up @@ -228,8 +228,7 @@ def __set__(self, instance, value):
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:
if not router.allow_relation(value, instance):
raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' %
(value, instance._state.db, value._state.db))
raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value)

related_pk = tuple([getattr(instance, field.attname) for field in self.related.field.foreign_related_fields])
if None in related_pk:
Expand Down Expand Up @@ -328,8 +327,7 @@ def __set__(self, instance, value):
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:
if not router.allow_relation(value, instance):
raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' %
(value, instance._state.db, value._state.db))
raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value)

# 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
Expand Down

0 comments on commit 07a73a2

Please sign in to comment.