[patch] Incorrect joins in many to many kwarg queries
|Reported by:||Owned by:||Adrian Holovaty|
|Component:||Database layer (models, ORM)||Version:|
|Severity:||normal||Keywords:||magic-removal unit test failure|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As a result of the lack of unit tests for many-to-many kwarg queries, the patch committed as r1792 introduced some backwards incompatibilities in the results returned by kwarg queries. Specifically, the join reuse behaviour of r1792 causes the join required for many-to-many intermediate table to be overwritten by the join required for the related table, resulting in an incorrect result set. This patch fixes this problem, and adds unit tests to prevent it from occurring again.
In addition, this patch adds the ability to form "reverse" many-to-many queries: i.e., kwarg queries starting on the class that does not contain the ManyToManyField. This was not previously possible, although the DB API docs imply that it should be. This feature is also unit tested.
This patch is provided against the magic-removal branch.