Code

Opened 2 years ago

Closed 2 years ago

#17315 closed Bug (duplicate)

.exclude(a, b) does not operate on a single related record

Reported by: absoludity@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm not sure if this is an implementation error, or a documentation error, but according to the documentation for filter/exclude spanning multi-valued relationships[1]:

"Everything inside a single filter() call is applied simultaneously to filter out items matching all those requirements. Successive filter() calls further restrict the set of objects, but for multi-valued relations, they apply to any object linked to the primary model, not necessarily those objects that were selected by an earlier filter() call."

"All of this behavior also applies to exclude(): all the conditions in a single exclude() statement apply to a single instance (if those conditions are talking about the same multi-valued relation)"

yet I can create a test [2] which seems to show this is not the case. The filter seems to do the correct thing, but the .exclude() call applies multiple args inside the call to separate instances [3]

[1] https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships
[2] http://paste.ubuntu.com/754721/ which, when run, results in http://paste.ubuntu.com/754723/
[3] http://paste.ubuntu.com/754742/

Attachments (1)

django-exclude-bug.diff (2.2 KB) - added by absoludity@… 2 years ago.
Diff adding failing test

Download all attachments as: .zip

Change History (2)

Changed 2 years ago by absoludity@…

Diff adding failing test

comment:1 Changed 2 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Yes, these tests show that the generated SQL doesn't match the documentation.

I believe this problem was already reported in #14645.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.