Opened 11 years ago

Closed 11 years ago

#20337 closed Cleanup/optimization (fixed)

ValueError when database router prevents relation is unclear

Reported by: Dan Loewenherz Owned by: Tim Graham <timograham@…>
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:2 by Simon Charette, 11 years ago

Keywords: router added; copy removed
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
UI/UX: unset
Version: 1.5master

The exception message re-wording makes sense.

comment:3 by Tim Graham <timograham@…>, 11 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 07a73a2714a504ae487112c1679977fccc19b159:

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

Note: See TracTickets for help on using tickets.
Back to Top