Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#35318 closed Cleanup/optimization (invalid)

QuerySet.exclude() docs contain a potentially misleading statement regarding the restrictiveness of examples.

Reported by: P1car00n Owned by: nobody
Component: Documentation Version: 5.0
Severity: Normal Keywords: QuerySet, Clarification, Accuracy
Cc: P1car00n Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In the Django documentation for the exclude() method, there's a statement comparing two examples where one is claimed to be more restrictive than the other. However, upon careful examination, it appears that the statement is inaccurate.

The documentation states:

"The second example is more restrictive."

However, this statement contradicts the actual behavior of the examples provided:

First Example:

Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3), headline="Hello")

This example excludes entries where both conditions (pub_date being later than January 3, 2005, and headline being "Hello") are true. It is more restrictive than the second example because it requires both conditions to be false for an entry to be excluded.

Second Example:

Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3)).exclude(headline="Hello")

This example excludes entries where either condition (pub_date being later than January 3, 2005, or headline being "Hello") is true. It is less restrictive than the first example because it allows for excluding entries based on either condition being true.

The issue is very easy to fix, but I wanted somebody with more experience with SQL to have a look first.

Change History (2)

comment:1 by Mariusz Felisiak, 8 months ago

Resolution: invalid
Status: newclosed
Summary: The documentation for Django's exclude() method contains a potentially misleading statement regarding the restrictiveness of two examples provided.QuerySet.exclude() docs contain a potentially misleading statement regarding the restrictiveness of examples.

Thanks for this report, however I don't see anything wrong or misleading in the current wording. The second example is called "more restrictive" because more rows will be excluded.

comment:2 by P1car00n, 8 months ago

Thanks for considering my report. I just wanted to suggest a possible clarification regarding the wording then. Instead of "more restrictive," perhaps we could use "more exclusionary" to describe the second example? This could help avoid confusion about the intention behind the term. What do you think?

P.S.
While it's true that the second example excludes more rows, I feel that the term "restrictive" in the context of querying refers to how narrowly or precisely the conditions filter the results, not necessarily the quantity of rows excluded.

Version 0, edited 8 months ago by P1car00n (next)
Note: See TracTickets for help on using tickets.
Back to Top