Changes between Initial Version and Version 2 of Ticket #12402


Ignore:
Timestamp:
Dec 18, 2009, 1:56:10 PM (14 years ago)
Author:
jbronn
Comment:

The problem is not GeoDjango related at all, and applies to the entire Oracle backend.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12402

    • Property Keywords oracle defer added
    • Property Owner changed from nobody to jbronn
    • Property Summary Deferring geometry field causes invalid results or crashQuerySet.defer does not work properly on Oracle
    • Property Component GISDatabase layer (models, ORM)
    • Property Status newassigned
  • Ticket #12402 – Description

    initial v2  
    1 If geometry field is not last and .defer('geom') is used results are populated incorrectly.
    2 
    3 It seems that geometry field is always counted in fields in even it is marked as deferred.
     1The machinery in `OracleQuery.resolve_columns` does not take into account any fields that are deferred.  Seeing this error depends on the order of the fields, and how they are handled by `OracleQuery.convert_values` -- which is probably why it's missed in the test suite.  Here's an example model that demonstrates the problem:
    42
    53{{{
     4#!python
     5from django.db import models
     6
    67class MyModel(models.Model):
    7     geom = models.PointField()
    8     num = models.IntegerField()
     8     num = models.FloatField()
     9     geom = models.CharField(max_length=128)
    910
    10     objects = models.GeoManager()
     11}}}
    1112
    12 >>> MyModel(geom=Geometry('POINT(10 10)'),num=1).save()
    13 >>> my_objs = MyModel.objects.defer('geom').all()
    14 >>> print my_objs
    15 >>> []
     13Here's how to raise it:
     14{{{
     15>>> MyModel.objects.create(num=5.0, name='Foobar')
     16<MyModel: MyModel object>
     17>>> qs = MyModel.objects.defer('num')
     18>>> print qs
     19Traceback (most recent call last):
     20  File "<ipython console>", line 1, in <module>
     21  File "C:\Python25\lib\site-packages\IPython\Prompts.py", line 552, in __call__
     22    manipulated_val = self.display(arg)
     23  File "C:\Python25\lib\site-packages\IPython\Prompts.py", line 578, in _display
     24    return self.shell.hooks.result_display(arg)
     25  File "C:\Python25\lib\site-packages\IPython\hooks.py", line 141, in __call__
     26    ret = cmd(*args, **kw)
     27  File "C:\Python25\lib\site-packages\IPython\hooks.py", line 171, in result_display
     28    out = pformat(arg)
     29  File "C:\Python25\lib\pprint.py", line 111, in pformat
     30    self._format(object, sio, 0, 0, {}, 0)
     31  File "C:\Python25\lib\pprint.py", line 129, in _format
     32    rep = self._repr(object, context, level - 1)
     33  File "C:\Python25\lib\pprint.py", line 195, in _repr
     34    self._depth, level)
     35  File "C:\Python25\lib\pprint.py", line 207, in format
     36    return _safe_repr(object, context, maxlevels, level)
     37  File "C:\Python25\lib\pprint.py", line 292, in _safe_repr
     38    rep = repr(object)
     39  File "C:\django\trunk\django\db\models\query.py", line 61, in __repr__
     40    data = list(self[:REPR_OUTPUT_SIZE + 1])
     41  File "C:\django\trunk\django\db\models\query.py", line 76, in __len__
     42    self._result_cache.extend(list(self._iter))
     43  File "C:\django\trunk\django\db\models\query.py", line 261, in iterator
     44    for row in self.query.results_iter():
     45  File "C:\django\trunk\django\db\models\sql\query.py", line 292, in results_iter
     46    row = self.resolve_columns(row, fields)
     47  File "C:\django\trunk\django\db\backends\oracle\query.py", line 54, in resolve_columns
     48    values.append(self.convert_values(value, field))
     49  File "C:\django\trunk\django\db\backends\oracle\query.py", line 74, in convert_values
     50    value = float(value)
     51ValueError: invalid literal for float(): Foobar
    1652}}}
     53
     54The problem reveals itself here because although we've deferred the `FloatField`, it's instance is still passed into `convert_values` with the value associated with the `CharField`.
     55
Back to Top