Opened 12 years ago
Closed 12 years ago
#20337 closed Cleanup/optimization (fixed)
ValueError when database router prevents relation is unclear
Reported by: | Dan Loewenherz | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | router |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I'm using a custom database router to manage queries between two databases.
In my router, the allow_relation
method was set incorrectly, and as a result, two models from separate apps weren't allowed to reference each other. The ValueError I received looked like this:
Cannot assign "<ContentType: xxx>": instance is on database "default", value is on database "default
I opened up the source that raised this error, and saw this line:
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))
The databases that these objects are on had nothing to do with how my router was routing the query, and kind of led me on a wild goose chase until I opened up the source. I would suggest a copy change to something like: "Cannot assign "%r": the current database router prevents this relation."
Change History (3)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Keywords: | router added; copy removed |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
UI/UX: | unset |
Version: | 1.5 → master |
The exception message re-wording makes sense.
comment:3 by , 12 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
PR @ https://github.com/django/django/pull/1035