#13692: Wrong ORM in complex filter
-------------------------------+--------------------------------------------
Reporter: myneur | Owner:
Status: new | Milestone:
Component: ORM aggregation | Version: 1.1
Keywords: filter, Q objects | Stage: Unreviewed
Has_patch: 0 |
-------------------------------+--------------------------------------------
== With Models: ==
{{{
class Professional(models.Model):
hits = models.PositiveIntegerField()
class Article(models.Model):
hits = models.PositiveIntegerField()
authors = models.ManyToManyField(Professional)
class Query(models.Model):
hits = models.PositiveIntegerField()
author = models.ForeignKey(Professional, blank = True, null =
True)
}}}
== A Query: ==
{{{
Professional.objects.annotate(article_hits=Sum("article__hits"),
query_hits=Sum("query__hits")).exclude(Q(article_hits=None)&Q(query_hits=None))
}}}
Produces exactly the same SQL as:
{{{
...exclude(Q(article_hits=None)|Q(advice_hits=None))
...filter(Q(article_hits=None)&Q(advice_hits=None))
...filter(Q(article_hits=None)|Q(advice_hits=None))
}}}
All of these queries produces a SQL with exactly the same last clause:
{{{
.... HAVING (SUM("articles_article"."hits") IS NULL AND
SUM("solutions_query"."hits") IS NULL)
}}}
It doesn't respond to filter/exclude or &| operator.
(and also the result is the same)
--
Ticket URL: <http://code.djangoproject.com/ticket/13692>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.