Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#13692 closed (duplicate)

Wrong ORM in complex filter

Reported by: myneur Owned by:
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: filter, Q objects
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Change History (2)

comment:1 by None, 14 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of http://code.djangoproject.com/ticket/11293. Well not exactly but the patch should be done together. the other has a patch will link it back here.

comment:2 by Anssi Kääriäinen, 12 years ago

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top