Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10757 closed (fixed)

GeoManager.values does not properly select primary keys across relations

Reported by: dgouldin 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:

Description

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)
>>> b.save()

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

>>> 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 dgouldin 5 years ago.
10757_v2.diff (5.6 KB) - added by jbronn 5 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Component changed from Uncategorized to GIS
  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.0 to SVN

comment:2 Changed 5 years ago by dgouldin

  • Cc dgouldin@… added
  • Has patch set

Changed 5 years ago by dgouldin

Changed 5 years ago by jbronn

comment:3 Changed 5 years ago by Alex

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

Closed in r10434

comment:4 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.