Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13250 closed (fixed)

auth.Message ignores directions from database router

Reported by: chris@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords: multidb, orm
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm using django-multidb-router from here: http://github.com/jbalogh/django-multidb-router With two database definitions, a read_only_user and a read_write_user (with the intentions of having multiple read-only definitions).

As far as I can tell, all reads get directed to the read_only_user and all writes get detected to read_write_user. That is, until contrib.Admin tries to create a new user message for a save() which for tries to write with the read_only_user and fails.

When overriding auth.Message.save() with an empty function, the admin interface resumes working as expected, with reads and writes being sent to the appropriate databases.

From what I guess by looking at the traceback, RelatedManager is overriding get_query_set() to set the query-set's DB. But when the create() call gets down to models.query.QuerySet.create(), obj.save() (line 350) is called, and forces using to self.db, negating any direction from the Router.

Change History (3)

comment:1 Changed 5 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This looks like an oversight in the create() call on foreign keys -- the write database isn't being correctly selected on the create call. Strangely, get_or_create() *is* implemented correctly. The fix is trivial; I just need to find the missing test case.

comment:2 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12895]) Fixed #13250 -- Corrected a problem with the use of routing rules on the create() call on a Foreign Key. Thanks to chris@… for the report.

comment:3 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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