Opened 15 years ago

Closed 15 years ago

Last modified 13 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: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 15 years ago.
initial patch, tests coming

Download all attachments as: .zip

Change History (7)

comment:1 by James Turk, 15 years ago

comment:2 by Jacob, 15 years ago

milestone: 1.11.2

Not a blocker for 1.1.

comment:3 by James Turk, 15 years ago

Owner: changed from nobody to James Turk
Status: newassigned

by James Turk, 15 years ago

Attachment: 11489.diff added

initial patch, tests coming

comment:4 by James Turk, 15 years ago

Has patch: set
Needs tests: set

comment:5 by jbronn, 15 years ago

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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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