diff --git a/sqlalchemy_utils/aggregates.py b/sqlalchemy_utils/aggregates.py index 9005e108..0b4d2ce5 100644 --- a/sqlalchemy_utils/aggregates.py +++ b/sqlalchemy_utils/aggregates.py @@ -534,6 +534,10 @@ def update_generator_registry(self): ) def construct_aggregate_queries(self, session, ctx): + if not self.generator_registry: + # short-circuit looping through objects if there are no aggregates defined + return + object_dict = defaultdict(list) for obj in session: for class_ in self.generator_registry: