Opened 14 years ago

Closed 13 years ago

#14893 closed Bug (fixed)

TypeError when accessing deferred (defer(..)) geometry field when using proxy geographic model

Reported by: mal Owned by: nobody
Component: GIS Version: dev
Severity: Normal Keywords: proxy, gis, defer, TypeError
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

We are getting
"TypeError: cannot set ... GeometryProxy with value of type: <type 'int'>"
when accessing deferred (defer(..)) geometry field when using proxy geographic model

Consider the models like this -

from django.contrib.gis.db import models
class BaseModel (models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50)
    text = models.CharField(max_length=50)
    location = models.PointField()
    
    objects = models.GeoManager()

class ProxyModel (BaseModel):
    class Meta:
        proxy = True

Then reading the deferred location via the proxy class will fail:

#create test object
BaseModel(name='test object', text='some text', location='POINT (3400000 6700010)').save()

#load same object via the proxy class, deferring location
#and try to access that location attribute 
o = ProxyModel.objects.defer("location")[0]
print o.location

The last line fails with the following error:

  File "c:\test\django-trunk\django\db\models\query_utils.py", line 102, in __get__
    instance._state.db).get(),
  File "c:\test\django-trunk\django\db\models\query.py", line 344, in get
    num = len(clone)
  File "c:\test\django-trunk\django\db\models\query.py", line 82, in __len__
    self._result_cache = list(self.iterator())
  File "c:\test\django-trunk\django\db\models\query.py", line 283, in iterator
    obj = model_cls(**dict(zip(init_list, row_data)))
  File "c:\test\django-trunk\django\db\models\base.py", line 353, in __init__
    setattr(self, field.attname, val)
  File "c:\test\django-trunk\django\contrib\gis\db\models\proxy.py", line 60, in __set__
    raise TypeError('cannot set %s GeometryProxy with value of type: %s' % (obj.__class__.__name__, type(value)))
TypeError: cannot set ProxyModel_Deferred_id_name_text GeometryProxy with value of type: <type 'int'>

Using the only(...) method results in the same error.
No problems using non-Geographic models, or/and when deferring non-geometrical fields.

Attachments (1)

proxy-test.tar (10.5 KB ) - added by anonymous 14 years ago.

Download all attachments as: .zip

Change History (5)

by anonymous, 14 years ago

Attachment: proxy-test.tar added

comment:1 by anonymous, 14 years ago

See the test case and more details proxy-test.tar

comment:2 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:3 by James Addison, 14 years ago

Severity: Normal
Type: Bug

comment:4 by anonymous, 13 years ago

Easy pickings: unset
Resolution: fixed
Status: newclosed
UI/UX: unset

This issue seems to be fixed as a result of #15790 ([16228]) - the test (after adopting for 1.4) passes now.

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