Django

Code

Ticket #12717 (closed: fixed)

Opened 6 months ago

Last modified 5 months ago

query.as_sql crashes with multi-db and master/slave routing

Reported by: jbalogh Assigned to: nobody
Milestone: 1.2 Component: Database layer (models, ORM)
Version: 1.2-alpha Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

To trigger this, you need a "default" and an "other" database setup, and they both can't be sqlite.

When you call str on a QuerySet?.Query object, it doesn't know about QuerySet?.db so it falls back to the default database. But the subquery knows what database to use (other), so the subquery compiles against a different database than the parent.

Attaching a failing test. The fix is probably to push using down to the Query, but I'm not sure.

The easy workaround is to call Query.get_compiler().as_sql with the correct using parameter.

Attachments

as_sql.diff (1.0 kB) - added by jbalogh on 01/27/10 23:43:52.
Failing test for as_sql with multi-db and master/slave

Change History

01/27/10 23:43:52 changed by jbalogh

  • attachment as_sql.diff added.

Failing test for as_sql with multi-db and master/slave

01/30/10 21:34:55 changed by russellm

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.2.

The specific use case you mention is definitely a problem, but I think there is might be something slightly deeper going on here - cross-database joins should be using the allow_relation check; if a relation isn't allowed, then the inner query should be rolled out to a result set, rather than trying to do an inner query in SQL.

03/10/10 09:27:23 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [12755]) Fixed #12717 -- Corrected a problem with subqueries when using multidb routing. Thanks to Jeff Balogh for the report.


Add/Change #12717 (query.as_sql crashes with multi-db and master/slave routing)




Change Properties
Action