#24770: Model instances are dropped by annotate when reverse foreign key is 
empty.
----------------------------------------------+--------------------
     Reporter:  Ian-Foote                     |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.8
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 I ran across an odd interaction between `annotate`, `Sum`, `Case`, `When`
 and a reverse `ForeignKey`. I've prepared a [https://github.com/Ian-Foote
 /django-annotate-bug/blob/master/bug/tests/test_query.py#L10-L24 minimal
 testcase].

 The query generated by the annotate looks like:
 {{{
 SELECT "bug_post"."id", "bug_post"."created", SUM(CASE WHEN
 "bug_comment"."created" > ("bug_post"."created") THEN 1 ELSE 0 END) AS
 "unread_comments" FROM "bug_post" INNER JOIN "bug_comment" ON (
 "bug_post"."id" = "bug_comment"."post_id" ) GROUP BY "bug_post"."id",
 "bug_post"."created"
 }}}

 I initially ran into this on postgres, but my minimal testcase also shows
 it on sqlite.

--
Ticket URL: <https://code.djangoproject.com/ticket/24770>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.07b132dc3da19baffe823c1eeb4e5e2e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to