#23797: SQL generated for negated F() expressions is incorrect -------------------------------------+------------------------------------- Reporter: mssnlayam | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.7 (models, ORM) | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: | Needs documentation: 0 Has patch: 0 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by akaariai): Yes, .exclude() should be the complement of .filter(). As said in comment:2 the `WHERE (length = width)) IS NOT true` way is just way too slow at least on PostgreSQL (always a sequential scan according to my tests). Going for the NOT ((length = width) AND (length IS NULL) AND (width IS NULL)) should likely work. I'd like to do this in the Lookup class. We can't do this directly in as_sql() as we don't have enough context there. Maybe a new method `get_extra_restriction(self, is_negated)` could work. The method returns an expression (a Lookup instance or WhereNode instance) that will be ANDed to the lookup's main condition. I'll try to find the time to write a small proof of concept. -- Ticket URL: <https://code.djangoproject.com/ticket/23797#comment:6> 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/067.f1bbe7e102fecfabb5ec6c3766dc4a42%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.