#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. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.7d695f1d3a5163744bd802cfad0a1d4a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.