Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#10888 closed (fixed)

Inserting model with GeometryField as None crashes on Oracle

Reported by: Jani Tiainen Owned by: jbronn
Component: GIS Version: dev
Severity: Keywords: oracle gis null
Cc: Matt Boersma Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

myapp/models.py:

from django.contrib.gis.db import models

class TestModel (models.Model):
    loc = models.GeometryField(null=True, blank=True)
    
    objects = models.GeoManager()

If I run code:

>>> from myapp.models import TestModel
>>> t = TestModel()
>>> t.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "d:\work\django-trunk\django\db\models\base.py", line 407, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "d:\work\django-trunk\django\db\models\base.py", line 483, in save_base
    result = manager._insert(values, return_id=update_pk)
  File "d:\work\django-trunk\django\db\models\manager.py", line 177, in _insert
    return insert_query(self.model, values, **kwargs)
  File "d:\work\django-trunk\django\db\models\query.py", line 1037, in insert_query
    return query.execute_sql(return_id)
  File "d:\work\django-trunk\django\db\models\sql\subqueries.py", line 320, in execute_s
    cursor = super(InsertQuery, self).execute_sql(None)
  File "d:\work\django-trunk\django\db\models\sql\query.py", line 2310, in execute_sql
    cursor.execute(sql, params)
  File "d:\work\django-trunk\django\db\backends\util.py", line 19, in execute
    return self.cursor.execute(sql, params)
  File "d:\work\django-trunk\django\db\backends\oracle\base.py", line 433, in execute
    raise e
DatabaseError: ORA-00932: inconsistent datatypes: expected MDSYS.SDO_GEOMETRY got CHAR

Attachments (2)

orcl_null_v1.diff (2.3 KB ) - added by jbronn 16 years ago.
orcl_null_v2.diff (5.7 KB ) - added by jbronn 16 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Jani Tiainen, 16 years ago

Further investigation indicates that this is more likely a Bug in cx_Oracle than Geodjango framework.

comment:2 by Jani Tiainen, 16 years ago

Quote from Anthony Tuininga on cx-oracle-users list:

This is expected behavior, unfortunately. Oracle requires a type to be
specified and if all you supply is None cx_Oracle has no choice but to
assume something. And CHAR seems the most likely to cause the least
difficulties. cx_Oracle currently has no way of binding in Oracle
object values like MDSYS.SDO_GEOMETRY.

So this is now real problem since you cant have null geometries easily.

by jbronn, 16 years ago

Attachment: orcl_null_v1.diff added

in reply to:  2 comment:3 by jbronn, 16 years ago

Keywords: null added
Needs tests: set
Owner: changed from nobody to jbronn
Triage Stage: UnreviewedDesign decision needed

Replying to jtiai:

For the rest of us, this is the thread from the cx_Oracle mailing list.

So this is now real problem since you cant have null geometries easily.

I agree it's a problem. But should we hack GeoDjango, as my attached patch does to just use NULL for the placeholder and omit a parameter? Or should we wait until the real underlying problem cx_Oracle is solved?

Until I'm convinced otherwise, I'm -1 on my own patch because (i) it's a hack, (ii) needs tests and (iii) it does not address other NULL geometry related issues, e.g., UPDATE queries (.update(geom_field=None)).

by jbronn, 16 years ago

Attachment: orcl_null_v2.diff added

comment:4 by jbronn, 16 years ago

Has patch: set
milestone: 1.1
Needs tests: unset
Status: newassigned
Triage Stage: Design decision neededAccepted

Alright, the v2 patch has grown on me and I'm +1 now. Specifically, I just re-enabled the existing null geometry tests for Oracle, .update() queries aren't affected by the problem, and the 'hackishness' only applies for Oracle -- which is par for the course.

comment:5 by jbronn, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [10631]) Fixed #10888 -- May now insert NULL GeometryField values on Oracle.

comment:6 by jbronn, 16 years ago

(In [10632]) [1.0.X] Fixed #10888 -- May now insert NULL GeometryField values on Oracle.

Backport of r10631 from trunk.

comment:7 by Matt Boersma, 16 years ago

Cc: Matt Boersma added

comment:8 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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