#32896: Exclude on expressions not being negated as expected -------------------------------------+------------------------------------- Reporter: Alex | Owner: nobody Henman | Type: Bug | Status: new Component: Database | Version: 3.2 layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- Quite similar to #23797 which looks like it was fixed in 3.2.
Consider the same model definition: {{{ #!python from django.db import models class Rectangle(models.Model): length = models.IntegerField(null=True) width = models.IntegerField(null=True) }}} Then compare the behaviour of excluding when directly accessing the field vs. using an alias or annotation: {{{ #!python In [5]: str(Rectangle.objects.exclude(length=123).values("pk").query) Out[5]: 'SELECT "geometry_rectangle"."id" FROM "geometry_rectangle" WHERE NOT ("geometry_rectangle"."length" = 123 AND "geometry_rectangle"."length" IS NOT NULL)' In [6]: str(Rectangle.objects.alias(aliased_length=F("length")).exclude(aliased_length=123).values("pk").query) Out[6]: 'SELECT "geometry_rectangle"."id" FROM "geometry_rectangle" WHERE NOT ("geometry_rectangle"."length" = 123)' In [7]: str(Rectangle.objects.annotate(aliased_length=F("length")).exclude(aliased_length=123).values("pk").query) Out[7]: 'SELECT "geometry_rectangle"."id" FROM "geometry_rectangle" WHERE NOT ("geometry_rectangle"."length" = 123)' }}} The expected behaviour would be that when using an alias or annotation, the {{{IS NOT NULL}}} condition would be added when using exclude. -- Ticket URL: <https://code.djangoproject.com/ticket/32896> 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/053.3a18abd6dc785472bc567c24ee70d2b5%40djangoproject.com.