#35154 closed New feature (wontfix)
QuerySet implements `contains` but not `__contains__` — at Version 2
| Reported by: | fidoriel | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.0 |
| Severity: | Normal | Keywords: | queryset contains |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
This is a similar proposal to #31561, but it is not the same. Currently using x in myQuerySet results in Python using the fallback solution: https://docs.python.org/3/reference/expressions.html#membership-test-details because https://groups.google.com/g/django-developers/c/NZaMq9BALrs/m/OCNTh6QyCAAJ decided to implement contains in #24141.
I think it is only consistent to have the same behavior implemented in __contains__. I would expect that, it is also a more efficient implementation and unifies Django behavior. Nevertheless, documentation is needed why this inconsistency exists. I was not able to find a reason. Because the mailing list agreed on adding contains, this is discussed behavior. Why was __contains__ not added in the first place? To not have breaking changes? I cannot see what would break.
As said in #31561 a queryset could be a collection to make typing easier. But this is not the intention of this issue.
Change History (2)
comment:1 by , 21 months ago
| Description: | modified (diff) |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
| Type: | Uncategorized → New feature |
comment:2 by , 21 months ago
| Description: | modified (diff) |
|---|
Have you read the discussion that you mention in the ticket? or comments in #24141? The entire discussion is about
__contains__and there was a consensus to addcontains()instead.