Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#11489 closed (fixed)

annotate fails when values is used via a GeoManager

Reported by: James Turk Owned by: James Turk
Component: GIS Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:


Attempting to do a query like Profile.objects.values('role').annotate(num=Count('id')) does not add a 'num' attribute despite generating seemingly correct SQL.

This was tested against r11247 with PostGIS

from django.conf import settings
from django.db.models import Manager
from django.contrib.auth.models import User
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
class Profile(models.Model):
    user = models.OneToOneField(User, related_name='profile')
    role = models.CharField(max_length=5, choices=ROLES, default='other')
    # ... extra fields removed ...
    objects = models.GeoManager()
    non_geo_manager = Manager()
>>> Profile.objects.values('role').annotate(num=Count('id'))._as_sql()
('SELECT U0."role", COUNT(U0."id") AS num FROM "people_profile" U0 GROUP BY U0."role"', ())
>>> Profile.objects.values('role').annotate(num=Count('id'))
[{'role': u'other'}, {'role': u'dev'}]                                      # notice that 'num' was not added
>>> Profile.non_geo_manager.values('role').annotate(num=Count('id'))._as_sql()
('SELECT U0."role", COUNT(U0."id") AS "num" FROM "people_profile" U0 GROUP BY U0."role"', ())
>>> Profile.non_geo_manager.values('role').annotate(num=Count('id'))
[{'num': 19, 'role': u'other'}, {'num': 1, 'role': u'dev'}]                 # num is added as expected

Attachments (1)

11489.diff (673 bytes) - added by James Turk 7 years ago.
initial patch, tests coming

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by James Turk

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 7 years ago by Jacob

milestone: 1.11.2

Not a blocker for 1.1.

comment:3 Changed 7 years ago by James Turk

Owner: changed from nobody to James Turk
Status: newassigned

Changed 7 years ago by James Turk

Attachment: 11489.diff added

initial patch, tests coming

comment:4 Changed 7 years ago by James Turk

Has patch: set
Needs tests: set

comment:5 Changed 7 years ago by jbronn

Resolution: fixed
Status: assignedclosed

(In [11251]) Fixed #11489 -- GeoQuery.resolve_columns now recognizes annotations; disabled problematic test cases on Oracle and added notes on why.

comment:6 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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