citusdata / django-multitenant

Python/Django support for distributed multi-tenant databases like Postgres+Citus
MIT License
712 stars 117 forks source link

Aggregations fail under certain conditions #63

Closed ledburyb closed 2 years ago

ledburyb commented 4 years ago

The following test case demonstrates one of the cases under which this fails. I investigated the cause of this and found it to be https://github.com/django/django/blob/7acef095d73322f45dcceb99afa1a4e50b520479/django/db/models/sql/compiler.py#L167. This alters the group by statement to just be grouped by 'id', but this doesn't work with Citus because we are dealing with composite primary keys and also need to include the tenant id in the group by.

    def test_aggregate(self):
        from .models import *
        projects = self.projects
        managers = self.project_managers
        unset_current_tenant()
        projects_per_manager = ProjectManager.objects.annotate(Count('project_id'))
        list(projects_per_manager)
JelteF commented 2 years ago

This was fixed in 2.4.0