Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#10888 closed (fixed)

Inserting model with GeometryField as None crashes on Oracle

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

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 6 years ago.
orcl_null_v2.diff (5.7 KB) - added by jbronn 6 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by jtiai

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

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

comment:2 follow-up: Changed 6 years ago by jtiai

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.

Changed 6 years ago by jbronn

comment:3 in reply to: ↑ 2 Changed 6 years ago by jbronn

  • Keywords null added
  • Needs tests set
  • Owner changed from nobody to jbronn
  • Triage Stage changed from Unreviewed to Design 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)).

Changed 6 years ago by jbronn

comment:4 Changed 6 years ago by jbronn

  • Has patch set
  • milestone set to 1.1
  • Needs tests unset
  • Status changed from new to assigned
  • Triage Stage changed from Design decision needed to Accepted

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 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:6 Changed 6 years ago by jbronn

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

Backport of r10631 from trunk.

comment:7 Changed 6 years ago by mboersma

  • Cc mboersma added

comment:8 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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