Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#34972 closed Bug (worksforme)

Aggregate with CombinedExpression resulting in NotImplemented instead of None after update from 3.2 -> 4.2

Reported by: ElRoberto538 Owned by: nobody
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords: CombinedExpression, NotImplemented, aggregate
Cc: David Sanders Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi we're currently updating to Django 4.2 before 3.2 extended support ends, and have discovered a weird issue with some of our queries. Using 3.2 our simplified example query below would return None, now it returns NotImplemented, is this expected behavior? Shouldn't CombinedExpression have empty_result_set_value set to None to maintain existing behavior?

OurModel.objects.none().aggregate(random_aggregate=Sum('field_1')/Count('field_2'))['random_aggregate']

Change History (4)

comment:1 by Natalia Bidart, 12 months ago

Resolution: worksforme
Status: newclosed

Hello, thank you for your report.

Could you please provide more details to help us triage this ticket? With the given information I can't reproduce the exception (I used a simple model I created for this report).
Specifically, we'd need:

  1. Your model definitions to exercise the provided query
  2. The exact exception you are getting

Feel free to re-open when you can provide further details.

comment:2 by Simon Charette, 12 months ago

I think the issue is slightly more complicated than setting empty_result_set_value = None as I would expect

OurModel.objects.none().aggregate(random_aggregate=Count('field_2')/Count('field_2'))['random_aggregate']

To return {"random_aggregate": 0}.

The fact NotImplemented is returned here is problematic though and I assume you have some third party apps that interacts with query compilation in a way that does not account for the fact that an aggregate expression that doesn't implement empty_result_set_value from an empty query should be evaluated by the database.

Last edited 12 months ago by Simon Charette (previous) (diff)

comment:3 by David Sanders, 12 months ago

Cc: David Sanders added

comment:4 by ElRoberto538, 12 months ago

We tried it in a different project and confirmed it worked, I expect this is an issue with the mssql-django DB connector.

Version 0, edited 12 months ago by ElRoberto538 (next)
Note: See TracTickets for help on using tickets.
Back to Top