Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#28765 closed Cleanup/optimization (fixed)

Clarify the documentation about what types the __in lookup accepts

Reported by: Дилян Палаузов Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal 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

Clarify, that [two underscores]in accepts any iterable (e.g. dict.keys())

diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -2520,7 +2520,7 @@ SQL equivalent::
 ``in``
 ~~~~~~
 
-In a given list.
+In a given iterable.
 
 Example::
 

Change History (7)

comment:1 Changed 3 weeks ago by Tim Graham

Component: Database layer (models, ORM)Documentation
Summary: Documentation __In lookupClarify the documentation about what types the __in lookup accepts
Triage Stage: UnreviewedAccepted

I'm not sure if "iterable" is the best term. For example, a string is iterable but isn't accepted.

comment:2 Changed 3 weeks ago by Дилян Палаузов

String is accepted, at least with Postgresql. E.g. when a column consists of a single letter x = models.Char(max_char=1, default='A') then ...objects.filter(x__in='ABC') is valid.

comment:3 Changed 3 weeks ago by Tim Graham

You're correct, but that generates WHERE x IN (A, B, C) which I don't think is intuitive.

comment:4 Changed 3 weeks ago by Дилян Палаузов

The SQL generated is correct for the case. I find it also intuitive, as this is also what I would have expected.

Back to he original question: are there any reason against clarifying that the _in lookup accepts iterables of any kind, not just lists?

comment:5 Changed 3 weeks ago by Tim Graham

Has patch: set

comment:6 Changed 3 weeks ago by GitHub <noreply@…>

Resolution: fixed
Status: newclosed

In 5587485d:

Fixed #28765 -- Clarified docs about what types the in lookup accepts.

comment:7 Changed 3 weeks ago by Tim Graham <timograham@…>

In bcaef2c9:

[2.0.x] Fixed #28765 -- Clarified docs about what types the in lookup accepts.

Backport of 5587485d49af8b32ab660854f751a234baa6610b from master

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