#27985: Converting `Foo.objects.filter(bar=None)` to an `IsNull` too early.
     Reporter:  Jarek Glowacki       |                    Owner:  Sergey
                                     |  Fedoseev
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  sql None NULL        |             Triage Stage:  Accepted
  transform                          |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
Changes (by Simon Charette):

 * cc: Simon Charette (added)


 John, I feel like using a `LOUTER` join is the appropriate behavior here.

 I assume the previous query was

 FROM group
 INNER JOIN user_groups ON (user_groups.group_id = group.id)
 WHERE user_groups.user_id = NULL

 And the new one is

 FROM group
 LEFT OUTER JOIN user_groups ON (user_groups.group_id = group.id)
 WHERE user_groups.user_id IS NULL

 Using `m2m__isnull=True` (or `reverse_fk__isnull=True`) always triggered
 this `LOUTER` AFAIK. I guess what broke here was to make `m2m=None` ->
 `m2m__isnull=True` which seems more appropriate given how SQL deals with
 `= NULL`.

 I guess we could get related and reverse related field `__exact` lookups
 to warn/error out when an unsaved object is passed as a value though, it
 looks like this was undefined behavior if it wasn't caught by the test
 suite. An other option would be to make the related
 `__exact=unsaved_object` lookup raise `EmptyResultSet` on compilation to
 prevent any query from taking place and restore the 1.11 behavior.

Ticket URL: <https://code.djangoproject.com/ticket/27985#comment:11>
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 
For more options, visit https://groups.google.com/d/optout.

Reply via email to