Opened 12 years ago

Last modified 6 years ago

#19493 closed Bug

annotate(Count()) does not work properly with django.db.backends.oracle — at Version 1

Reported by: kimvais@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords: oracle
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Anssi Kääriäinen)

An QuerySet operation like:
models.SomeModel.objects.filter(somecharfield=value).values("someintegerfield").annotate(Count("someintegerfield"))

return a QuerySet with no aggregate count, but multiple rows with someintegerfield__count=1

The correct SQL would be:

SELECT tablespace_somemodel.someintegerfield, COUNT(tablespace_somemodel.someintegerfield) AS someintegerfield__count
  FROM tablespace_somemodel WHERE tablespace_somemodel.somecharfield = 'value'
 GROUP BY tablespace_somemodel.someintegerfield;

This works fine on other backends.

Change History (1)

comment:1 by Anssi Kääriäinen, 12 years ago

Description: modified (diff)

What SQL do you get? settings.DEBUG = True + connection.queries should tell you the executed query easily.

Quickly checking it seems a QuerySet with multiple rows having someintegerfield__count=1 seems the correct answer for the query.

Note: See TracTickets for help on using tickets.
Back to Top