Opened 5 years ago

Closed 4 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: master
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


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\", line 102, in __get__
  File "c:\test\django-trunk\django\db\models\", line 344, in get
    num = len(clone)
  File "c:\test\django-trunk\django\db\models\", line 82, in __len__
    self._result_cache = list(self.iterator())
  File "c:\test\django-trunk\django\db\models\", line 283, in iterator
    obj = model_cls(**dict(zip(init_list, row_data)))
  File "c:\test\django-trunk\django\db\models\", line 353, in __init__
    setattr(self, field.attname, val)
  File "c:\test\django-trunk\django\contrib\gis\db\models\", 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 5 years ago.

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by anonymous

comment:1 Changed 5 years ago by anonymous

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

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

comment:2 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by jaddison

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 4 years ago by anonymous

  • Easy pickings unset
  • Resolution set to fixed
  • Status changed from new to closed
  • 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