Opened 13 years ago

Closed 12 years ago

Last modified 10 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


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:


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 Changed 12 years ago by None

Resolution: duplicate
Status: newclosed

This is a duplicate of Well not exactly but the patch should be done together. the other has a patch will link it back here.

comment:2 Changed 10 years ago by Anssi Kääriäinen

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