Opened 6 years ago

Closed 6 years ago

#19500 closed Bug (fixed)

Join reuse regression

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: charette.s@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


The commit 68847135bc9acb2c51c2d36797d0a85395f0cd35 for ticket #18748 caused a severe regression in join reuse. Chained filters for direct foreign keys do not reuse existing joins at all. For example


causes two joins instead of one.

The patch at fixes the issue and adds various test for join reuse. It actually simplifies the code a little.

As a bonus we can now correctly reuse joins in chained filter() calls when using reverse o2o fields.

I think I will commit the patch soon as currently the code isn't behaving nicely.

Change History (3)

comment:1 Changed 6 years ago by Simon Charette

Cc: charette.s@… added
Patch needs improvement: set

Added some comments on the patch over github.

comment:3 Changed 6 years ago by Anssi Kääriäinen <akaariai@…>

Resolution: fixed
Status: newclosed

In 3dcd435a0eb4380a3846e9c65140df480975687e:

Fixed #19500 -- Solved a regression in join reuse

The ORM didn't reuse joins for direct foreign key traversals when using
chained filters. For example:


produced two joins.

As a bonus, reverse onetoone filters can now reuse joins correctly

The regression was caused by the join() method refactor in commit

Thanks for Simon Charette for spotting some issues with the first draft
of the patch.

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