Opened 14 years ago
Closed 14 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)
Change History (5)
by , 14 years ago
Attachment: | proxy-test.tar added |
---|
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 14 years ago
Easy pickings: | unset |
---|---|
Resolution: | → fixed |
Status: | new → closed |
UI/UX: | unset |
Note:
See TracTickets
for help on using tickets.
See the test case and more details proxy-test.tar