Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19547 closed Bug (fixed)

Queryset.__or__ and caching of known related instances breaking

Reported by: Marc Tamlyn Owned by: Aymeric Augustin
Component: Database layer (models, ORM) Version: 1.5-beta-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you or together two querysets with known related instances then you can get some incorrect data:

If you do instance_1.foo_set.all() | instance_2.foo_set.all() then all of the foos will have foo.instance == instance1 even though foo.instance_id == instance2.pk.

I have a failing test case and a partial fix on github at https://github.com/mjtamlyn/django/compare/known-related-objects-queryset-or

The fix does ensure data is integral but it doesn't have the full efficiency improvement. I'm also working on a fix which solves the efficiency as well but it doesn't feel "right"...

Change History (5)

comment:1 by Marc Tamlyn, 12 years ago

Branch updated with a fix for the efficiency part of the test.

comment:2 by Aymeric Augustin, 12 years ago

Owner: changed from Marc Tamlyn to Aymeric Augustin
Status: newassigned
Triage Stage: UnreviewedAccepted

The patch looks good.

comment:3 by Aymeric Augustin, 12 years ago

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 07fbc6ae0e3b7742915b785c737b7e6e8a0e3503:

Fixed #19547 -- Caching of related instances.

When &'ing or |'ing querysets, wrong values could be cached, and crashes
could happen.

Thanks Marc Tamlyn for figuring out the problem and writing the patch.

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In 056ace0f395a58eeac03da9f9ee7e3872e1e407b:

[1.5.x] Fixed #19547 -- Caching of related instances.

When &'ing or |'ing querysets, wrong values could be cached, and crashes
could happen.

Thanks Marc Tamlyn for figuring out the problem and writing the patch.

Backport of 07fbc6a.

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