﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14893	TypeError when accessing deferred (defer(..)) geometry field when using proxy geographic model	mal	nobody	"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 - 
{{{
#!python
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:

{{{
#!python
#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."	Bug	closed	GIS	dev	Normal	fixed	proxy, gis, defer, TypeError		Accepted	0	0	0	0	0	0
