Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10757 closed (fixed)

GeoManager.values does not properly select primary keys across relations

Reported by: David Gouldin Owned by: nobody
Component: GIS Version: master
Severity: Keywords:
Cc: dgouldin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When using GeoManager.values to select a primary key from a foreign relation, GeoManager selects the primary key from its model rather than joining to the related model and selecting that model's primary key. See code sample below:

from django.contrib.gis.db import models

class Bar(models.Model):
    bar_field = models.BooleanField()

    objects = models.GeoManager()

class Foo(models.Model):
    foo_field = models.BooleanField()
    bar = models.ForeignKey(Bar)

    objects = models.GeoManager()

# ---

>>> from djtest.models import *

>>> Foo.objects.all().delete()
>>> Bar.objects.all().delete()

>>> b = Bar(id=50, bar_field=True)

>>> f = Foo(foo_field=True, bar=b)

>>> Foo.objects.values('id', 'bar__id').query.as_sql()
('SELECT "djtest_foo"."id", "djtest_foo"."id" FROM "djtest_foo"', ())

>>> Foo.objects.values('id', 'bar__id')[0]
{'bar__id': 1, 'id': 1}

Attachments (2)

10757.diff (4.4 KB) - added by David Gouldin 8 years ago.
10757_v2.diff (5.6 KB) - added by jbronn 8 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 8 years ago by Alex Gaynor

Component: UncategorizedGIS
milestone: 1.1
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted
Version: 1.0SVN

comment:2 Changed 8 years ago by David Gouldin

Cc: dgouldin@… added
Has patch: set

Changed 8 years ago by David Gouldin

Attachment: 10757.diff added

Changed 8 years ago by jbronn

Attachment: 10757_v2.diff added

comment:3 Changed 8 years ago by Alex Gaynor

Resolution: fixed
Status: newclosed

Closed in r10434

comment:4 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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