Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#11489 closed (fixed)

annotate fails when values is used via a GeoManager

Reported by: jamesturk Owned by: jamesturk
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:

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

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by jamesturk

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by jacob

  • milestone changed from 1.1 to 1.2

Not a blocker for 1.1.

comment:3 Changed 6 years ago by jamesturk

  • Owner changed from nobody to jamesturk
  • Status changed from new to assigned

Changed 6 years ago by jamesturk

initial patch, tests coming

comment:4 Changed 6 years ago by jamesturk

  • Has patch set
  • Needs tests set

comment:5 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:6 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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