Opened 4 years ago

Closed 4 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


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]

[2] which, when run, results in

Attachments (1)

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

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by absoludity@…

Diff adding failing test

comment:1 Changed 4 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.

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