Django

Code

Ticket #2080 (closed: duplicate)

Opened 2 years ago

Last modified 10 months ago

OR lookup across many-to-one relationships gives unexpected results

Reported by: akaihola Assigned to: adrian
Milestone: Component: Database wrapper
Version: Keywords:
Cc: mir@noris.de, mattimustang@gmail.com, yannvr@gmail.com Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If

  • model B has a foreign key on model A,
  • there is an a1 = A(field1=value1) object but no related B objects

and you do

A.objects.filter(Q(field1=value1) | Q(b__field2=value2))

the result will fail to include a1.

This is quite unexpected in my opinion, and I think the reason is that the resulting SQL query uses an inner join instead of an outer join.

Attachments

m2o_or_lookup_test.diff (1.3 kB) - added by akaihola on 06/04/06 11:24:07.
a test case for an OR lookup across a foreign key relation
m2o_or_lookup_test.2.diff (2.1 kB) - added by akaihola on 06/04/06 11:55:18.
Added testing with alternate syntax and checking what kind of join Django uses

Change History

06/04/06 11:24:07 changed by akaihola

  • attachment m2o_or_lookup_test.diff added.

a test case for an OR lookup across a foreign key relation

06/04/06 11:37:40 changed by akaihola

This might be the same issue as in ticket #1535, although that seems to be already fixed but it doesn't fix this.

06/04/06 11:40:15 changed by akaihola

Also #1801 resembles this a bit.

06/04/06 11:55:18 changed by akaihola

  • attachment m2o_or_lookup_test.2.diff added.

Added testing with alternate syntax and checking what kind of join Django uses

06/04/06 13:36:39 changed by mir@novell.de

  • cc set to mir@novell.de.

07/10/06 06:20:25 changed by mir@noris.de

  • cc changed from mir@novell.de to mir@noris.de.

07/10/06 23:23:54 changed by adrian

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #1801.

08/15/07 09:18:25 changed by Matthew Flanagan <mattimustang@gmail.com>

  • cc changed from mir@noris.de to mir@noris.de, mattimustang@gmail.com.

11/27/07 06:02:20 changed by Yopi <yannvr@gmail.com>

  • cc changed from mir@noris.de, mattimustang@gmail.com to mir@noris.de, mattimustang@gmail.com, yannvr@gmail.com.

Add/Change #2080 (OR lookup across many-to-one relationships gives unexpected results)




Change Properties
Action