#25467: Excluding an object with no ID excludes everything. -------------------------------------+------------------------------------- Reporter: skorokithakis | Owner: | HuffAndPuff Type: Bug | Status: assigned Component: Database layer | Version: 1.8 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by carljm): Some more musings on this: Our strongest existing precedent for the meaning of `None` in an ORM comparison is that `__exact=None` is equivalent to `__isnull=True`, or SQL `IS NULL`. If we accept that as a consistent semantic, it would imply that we should fix `__in=[val, None]` generally (not just for related fields) to remove the `None` from the `in` list and add an `OR IS NULL` clause alongside it. This seems better than the current behavior to me, but perhaps low priority. It would also imply that `.exclude(related_field=unsaved_instance)` would exclude records where the `related_field` FK is `NULL`. This is subtly different from the OPs requested behavior, which is that such an `exclude` would never exclude anything. I find the latter behavior (to consider `unsaved_instance` to match nothing, rather than matching NULL) more intuitive. Which means we either a) use different semantics for instance- with-None-pk in comparisons than we use for `None` in comparisons otherwise, b) accept a less-intuitive behavior for instance-with-None-pk for consistency with use of `None` elsewhere, or c) declare that the choice between (a) and (b) is too ambiguous (that I was wrong earlier when I said "there's no ambiguity"), and therefore we should just raise an exception after all. I think I would put these in preference order (a) (c) (b), but could live with any of them; and complexity-of-implementation could easily sway me to prefer (c) over (a). -- Ticket URL: <https://code.djangoproject.com/ticket/25467#comment:9> 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/071.5502e38aa89d75e222a80365ade3858d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.