Query Set Refactor handling of INNER JOINs
|Reported by:||khoobks||Owned by:||George Vilches|
|Component:||Database layer (models, ORM)||Version:||master|
|Severity:||Keywords:||query set refactor order_by inner join|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The best way for me to explain the issue I have discovered is to run the test case provided with this ticket. The test case is a modification of the many_to_one test case that comes with Django. I have commented out the "unnecessary" bits for clarity.
The problem that I am reporting is that due to the way that the ordering is expressed in the example, a join to the related table is necessary.
When performing any query on this model (except a count) an INNER JOIN is used in the SQL command. If we are trying to get all rows (from a table that contains some rows) using "all()", an INNER JOIN will be performed to the related table which, in the example contains no rows. This results in the "all()" function returning an empty query set which is incorrect. I think.
Change History (4)
comment:1 Changed 9 years ago by
|Component:||Core framework → Database wrapper|
|Owner:||changed from nobody to George Vilches|
|Status:||new → assigned|