Aggregate with inherited columns does not work as expected
class Thing(models.Model):
user = models.ForeignKey("auth.user")
creation_date = models.DateTimeField(_('Creation date'), default=datetime.datetime.now)
amount = models.PositiveIntegerField()
class Book(Thing):
blabla = models.ForeignKey("xyz")
# does not work
Book.objects.filter(user=request.user).aggregate(Sum('amount'))
# does work
Book.objects.filter(user=request.user).annotate(Sum('amount'))
# does work
Book.objects.filter(user=request.user).aggregate(Sum('book_ptr__amount'))
Change History
(4)
milestone: |
1.1 beta → 1.1
|
Triage Stage: |
Unreviewed → Accepted
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Component: |
ORM aggregation → Database layer (models, ORM)
|
(in [10466]) Fixed #10666 -- Corrected the handling of inherited fields with aggregate() and annotate(). Thanks to julienb for the report.