query.as_sql crashes with multi-db and master/slave routing
|Reported by:||jbalogh||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.2-alpha|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
Change History (4)
Changed 5 years ago by jbalogh
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