Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#12717 closed (fixed)

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

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

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 (1)

as_sql.diff (998 bytes ) - added by Jeff Balogh 14 years ago.
Failing test for as_sql with multi-db and master/slave

Download all attachments as: .zip

Change History (4)

by Jeff Balogh, 14 years ago

Attachment: as_sql.diff added

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

comment:1 by Russell Keith-Magee, 14 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

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.

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

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

comment:3 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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