dabapps / django-rest-framework-serialization-spec

DEPRECATED, see https://github.com/dabapps/django-readers instead
MIT License
11 stars 0 forks source link

Should we disallow combining aggregations? #28

Open pmg103 opened 4 years ago

pmg103 commented 4 years ago

As per https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#combining-multiple-aggregations:

Combining multiple aggregations with annotate() will yield the wrong results because joins are used instead of subqueries

Therefore I understand that if any serialization_spec contains multiple aggregations over different fields, eg:

serialization_spec = [
    ...
    {total_age: SumOf('users__age')},
    {total_height: SumOf('users__height')},
]

Then this will return the wrong result.

It occurs to me that we could do better than django on this (which merely notes that the wrong results would be returned in its docs) by either:

  1. Making this work somehow waves hands; or at least
  2. Making this illegal -- raise a validation error