#26789: ORM produces query with NULL instead of empty geometry
-------------------------------+--------------------
Reporter: sir-sigurd | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
{{{#!python
from test_app.models import City
from django.contrib.gis.geos.geometry import GEOSGeometry
City.objects.create(point=GEOSGeometry('POINT EMPTY', srid=4326))
}}}
raises error
{{{#!python
/home/sergey/dev/django/django/db/models/manager.pyc in
manager_method(self, *args, **kwargs)
83 def create_method(name, method):
84 def manager_method(self, *args, **kwargs):
---> 85 return getattr(self.get_queryset(), name)(*args,
**kwargs)
86 manager_method.__name__ = method.__name__
87 manager_method.__doc__ = method.__doc__
/home/sergey/dev/django/django/db/models/query.pyc in create(self,
**kwargs)
397 obj = self.model(**kwargs)
398 self._for_write = True
--> 399 obj.save(force_insert=True, using=self.db)
400 return obj
401
/home/sergey/dev/django/django/db/models/base.pyc in save(self,
force_insert, force_update, using, update_fields)
794
795 self.save_base(using=using, force_insert=force_insert,
--> 796 force_update=force_update,
update_fields=update_fields)
797 save.alters_data = True
798
/home/sergey/dev/django/django/db/models/base.pyc in save_base(self, raw,
force_insert, force_update, using, update_fields)
822 if not raw:
823 self._save_parents(cls, using, update_fields)
--> 824 updated = self._save_table(raw, cls, force_insert,
force_update, using, update_fields)
825 # Store the database on which the object was saved
826 self._state.db = using
/home/sergey/dev/django/django/db/models/base.pyc in _save_table(self,
raw, cls, force_insert, force_update, using, update_fields)
906
907 update_pk = bool(meta.has_auto_field and not pk_set)
--> 908 result = self._do_insert(cls._base_manager, using,
fields, update_pk, raw)
909 if update_pk:
910 setattr(self, meta.pk.attname, result)
/home/sergey/dev/django/django/db/models/base.pyc in _do_insert(self,
manager, using, fields, update_pk, raw)
945 """
946 return manager._insert([self], fields=fields,
return_id=update_pk,
--> 947 using=using, raw=raw)
948
949 def delete(self, using=None, keep_parents=False):
/home/sergey/dev/django/django/db/models/manager.pyc in
manager_method(self, *args, **kwargs)
83 def create_method(name, method):
84 def manager_method(self, *args, **kwargs):
---> 85 return getattr(self.get_queryset(), name)(*args,
**kwargs)
86 manager_method.__name__ = method.__name__
87 manager_method.__doc__ = method.__doc__
/home/sergey/dev/django/django/db/models/query.pyc in _insert(self, objs,
fields, return_id, raw, using)
1042 query = sql.InsertQuery(self.model)
1043 query.insert_values(fields, objs, raw=raw)
-> 1044 return
query.get_compiler(using=using).execute_sql(return_id)
1045 _insert.alters_data = True
1046 _insert.queryset_only = False
/home/sergey/dev/django/django/db/models/sql/compiler.pyc in
execute_sql(self, return_id)
1052 with self.connection.cursor() as cursor:
1053 for sql, params in self.as_sql():
-> 1054 cursor.execute(sql, params)
1055 if not (return_id and cursor):
1056 return
/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql,
params)
77 start = time()
78 try:
---> 79 return super(CursorDebugWrapper, self).execute(sql,
params)
80 finally:
81 stop = time()
/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql,
params)
62 return self.cursor.execute(sql)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):
/home/sergey/dev/django/django/db/utils.pyc in __exit__(self, exc_type,
exc_value, traceback)
92 if dj_exc_type not in (DataError, IntegrityError):
93 self.wrapper.errors_occurred = True
---> 94 six.reraise(dj_exc_type, dj_exc_value, traceback)
95
96 def __call__(self, func):
/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql,
params)
62 return self.cursor.execute(sql)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):
IntegrityError: ОШИБКА: нулевое значение в столбце "point" нарушает
ограничение NOT NULL
DETAIL: Ошибочная строка содержит (3, null).
}}}
The last query
{{{#!python
from django.db import connection
connection.queries[-1]['sql']
}}}
is
{{{#!python
u'INSERT INTO "test_app_city" ("point") VALUES (NULL) RETURNING
"test_app_city"."id"'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26789>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.4a1c7f326d0d8494f94bc6e4cbca1134%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.