[Django] #30639: Raise warning or error when user attempts an unsupported operation on a UNION queryset

2 views
Skip to first unread message

Django

unread,
Jul 15, 2019, 10:16:54 AM7/15/19
to django-...@googlegroups.com
#30639: Raise warning or error when user attempts an unsupported operation on a
UNION queryset
-------------------------------------+-------------------------------------
Reporter: dhimmel | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: union, filter,
Severity: Normal | warning
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
There is a major gotcha where several operations (such as `.filter` and
`.exclude`) do not have any effect if applied to a queryset that has
previously included a `.union` statement. See for example this
[StackOverflow](https://stackoverflow.com/a/49261966/4651668).

Here is a code example:

{{{
queryset_union = queryset_a.union(queryset_b)
queryset_union.filter(key=value)
}}}


The last command has no effect. Ideally, it should apply the requested
filter. However, from the [docs
comment](https://docs.djangoproject.com/en/2.2/ref/models/querysets/#union)
the following:

> In addition, only LIMIT, OFFSET, COUNT(*), ORDER BY, and specifying
columns (i.e. slicing, count(), order_by(), and values()/values_list())
are allowed on the resulting QuerySet. Further, databases place
restrictions on what operations are allowed in the combined queries. For
example, most databases don’t allow LIMIT or OFFSET in the combined
queries.

Therefore, without adding the functionality, it would make sense to
trigger a warning or raise an exception, such that users are aware that
their filter statement did not succeed. IMO this seems like a
`NotImplementedError`. However, a warning would be more backwards
compatible.

--
Ticket URL: <https://code.djangoproject.com/ticket/30639>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 15, 2019, 11:46:26 AM7/15/19
to django-...@googlegroups.com
#30639: Raise an error on unsupported operations following QuerySet.union().

-------------------------------------+-------------------------------------
Reporter: dhimmel | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: union, filter, | Triage Stage:
warning | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* type: Uncategorized => Bug
* version: 2.2 => master
* resolution: => duplicate


Comment:

Duplicate of #27995.

--
Ticket URL: <https://code.djangoproject.com/ticket/30639#comment:1>

Reply all
Reply to author
Forward
0 new messages