||= Python =||= sqlite =|| spatialite || GDAL || GEOS || Proj || Tests ||
|| 3.8.10 || 3.36.0 || 4.3.0a || 3.1.2 || 3.8.1 || 7.1.0 || PASS ||
|| 3.9.6 || 3.36.0 || 5.0.1 || 3.2.0 || 3.8.1 || 7.1.1 || FAIL ||
|| 3.9.6 || 3.36.0 || 5.0.1 || 3.3.1 || 3.9.1 || 8.0.1 || FAIL ||
|| 3.8.10 || 3.36.0 || 5.0.1 || 3.3.0 || 3.9.1 || 8.0.1 || FAIL ||
|| 3.9.6 || 3.36.0 || 5.0.1 || 3.2.2 || 3.9.1 || 8.0.0 || FAIL ||
|| 3.8.10 || 3.36.0 || 5.0.1 || 3.2.2 || 3.9.1 || 8.0.0 || FAIL ||
|| 3.9.2 || 3.35.0 || 5.0.1 || 3.2.2 || 3.9.1 || 8.0.0 || PASS ||
The tests were failing not for a GIS test, but on databse setup. For
exampe I had the same failure when runing the tests for `admin_inlines`.
The tests fail when setting up the database with this error.
{{{
File "/workspaces/django/django/db/backends/sqlite3/base.py", line 417, in
execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: error in trigger
ISO_metadata_reference_row_id_value_insert: no such column: rowid
}}}
At this point of failure `query` is `ALTER TABLE "new__django_admin_log"
RENAME TO "django_admin_log"`
I found that if I changed this
[https://github.com/django/django/blame/a56531ab1b772ee4ae94dd805f168761887354c6/django/contrib/gis/db/backends/spatialite/base.py#L77
line] back to the same behaviour as spatialite 4x then the suite will
pass.
I note that the [https://www.sqlite.org/draft/releaselog/current.html
release notes] for sqlite 3.36 say the following, which I'm assuming is
the cause of the issue here.
> An error is raised on any attempt to access the rowid of a VIEW or
subquery.
--
Ticket URL: <https://code.djangoproject.com/ticket/32935>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Claude Paroz (added)
* resolution: => needsinfo
* status: new => closed
* component: Uncategorized => GIS
* type: Uncategorized => Bug
Comment:
Thanks for the report. I can reproduce this issue, I also confirmed that
SQLite 3.36 compiled with `-DSQLITE_ALLOW_ROWID_IN_VIEW` works fine.
However I don't think that Django is at fault because calling
`InitSpatialMetaDataFull(1)` is the [https://www.gaia-
gis.it/fossil/libspatialite/wiki?name=PROJ.6 recommended way] for
SpatiaLite 5.
Can you try to report this on their bug tracker or
[https://groups.google.com/g/spatialite-users the mailing list]?
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:1>
Comment (by David Smith):
Thank you for your guidance here. :-)
I posted on the mailing list and received a response from Sandro.
https://groups.google.com/g/spatialite-users/c/SnNZt4AGm_o
It seems to me that this confirms it is a bug in Spatialite and/or
sqlite3.36.
Do you think it's worth adding a note to this page in the
[https://docs.djangoproject.com/en/3.2/ref/contrib/gis/install/geolibs/
docs]?
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:2>
Comment (by Mariusz Felisiak):
Thanks.
> Do you think it's worth adding a note to this page in the docs?
I don't think it's necessary. This ticket should be enough.
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:3>
Comment (by Federico Capoano):
Thanks for opening this ticket and linking useful information.
I found this while adding trying to deploy OpenWISP using Django 4.0 on
Ubuntu 22.04, but I have seen that the same application runs fine with
Django 3.2 on Ubuntu 22.04, so I wanted to ask you: are you're sure it's
not a bug on the Django side? And if yes, why?
Is it because the latest version of GeoDjango ships some new feature which
wasn't available in Django 3.2 and now this feature is broken on
Spatialite 5?
Thanks in advance.
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:4>
Comment (by SunyataZero):
Hi all, i get the error
{{{
django.db.utils.OperationalError: error in trigger
ISO_metadata_reference_row_id_value_insert: no such column: rowid
}}}
when following the GeoDjango tutorial
https://docs.djangoproject.com/en/4.1/ref/contrib/gis/tutorial/
My setup:
* Django 4.1
* Ubuntu 22.04
* sqlite 3.37.2
* libsqlite3-mod-spatialite 5.0.1-2build2
I hope this helps
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:5>
Comment (by sheppard):
I can confirm this is broken on Ubuntu 22.04 with the default apt library
versions. Here's another comment from spatialite-users that explains
what is going on:
https://groups.google.com/g/spatialite-users/c/5rKuVlIzwZY/m/ydEa4ir_AAAJ
I think this means that InitSpatialMetaDataFull(1) basically will not work
on Ubuntu 22.04 until the next version of libsqlite3-mod-spatialite is
released and packaged. While this isn't strictly a bug in Django, I think
it would be appropriate and helpful to fall back to InitSpatialMetaData(1)
if the "ISO_metadata_reference_row_id_value_insert" error is detected.
Can this ticket be reopened?
In the meantime, here's a one-liner that can be executed before running
./manage.py migrate on Ubuntu 22.04.
{{{
./manage.py shell -c "import
django;django.db.connection.cursor().execute('SELECT
InitSpatialMetaData(1);')";
./manage.py migrate
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:6>
Comment (by Mariusz Felisiak):
> Can this ticket be reopened?
As far as I'm aware, changing to the `InitSpatialMetaData()` in Django is
not an option. According to the `SpatiaLite`'s docs:
> ''"InitSpatialMetaData is still maintained so to not break historical
compatibility, but **should no longer be used**."''
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:7>
Comment (by S. Andrew Sheppard):
Yes, InitSpatialMetaDataFull would remain as the preferred option. The
fallback would be only for systems like Ubuntu 22.04 where using
InitSpatialMetaDataFull per the docs is not an option, because the
implementation in spatialite 5.0.1 (the latest released version) is
incompatible with sqlite 3.36 (and newer versions). In spite of the stern
warning on the PROJ.6 page, other parts of the documentation explain that
InitSpatialMetaDataFull and InitSpatialMetaData are highly compatible:
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=Upgrading+existing
+DB-files+to+5.0.0
Basically, it seems that the 5.0 schema created by InitSpatialMetaDataFull
is the same as the 4.0 schema created by InitSpatialMetaData, but with
additional tables needed to support librasterlite2. Many GeoDjango users
will probably be fine without raster support, so falling back to
InitSpatialMetaData seems like it should be reasonable for most cases.
That said, it is fair to argue that initializing a database with Django
and spatialite 5.0 should result in a full 5.0-compatible schema.
Fortunately, it appears that the CreateMissingSystemTables method also
described in that documentation does not break, so it could be used as
part of the fallback. Perhaps something like this would be appropriate:
{{{
cursor.execute("PRAGMA table_info(geometry_columns);")
if cursor.fetchall() == []:
if self.ops.spatial_version < (5,):
cursor.execute("SELECT InitSpatialMetaData(1)")
else:
try:
cursor.execute("SELECT
InitSpatialMetaDataFull(1)")
except OperationalError as e:
if "ISO_metadata_reference_row_id_value_insert" in
e.args[0]:
# Workaround for sqlite 3.36 and spatialite
5.0.1
cursor.execute("SELECT InitSpatialMetaData(1)")
cursor.execute("SELECT
CreateMissingSystemTables(1)")
else:
raise
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:8>
* cc: Jon Janzen (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:9>
Comment (by Federico Capoano):
I think a workaround for systems which will ship spatialite 5 by default
is needed to avoid newcomers to get stuck on this.
Moreover, managing this workaround on CI systems on github CI or travis is
painful and a huge waste of time.
Can we reopen this ticket please? Will the maintainers accept a patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:10>
Comment (by Alex Tomkins):
Replying to [comment:8 S. Andrew Sheppard]:
> That said, it is fair to argue that initializing a database with Django
and spatialite 5.0 should result in a full 5.0-compatible schema.
Fortunately, it appears that the CreateMissingSystemTables method also
described in that documentation does not break, so it could be used as
part of the fallback. Perhaps something like this would be appropriate:
Just upgraded a project to Django 4.2, and this doesn't work for me -
running `CreateMissingSystemTables(1)` results in the same problem:
{{{
django.db.utils.OperationalError: error in trigger
ISO_metadata_reference_row_id_value_insert: no such column: rowid
}}}
The two workarounds which don't result in errors, your one liner in an
earlier post:
{{{
./manage.py shell -c "import
django;django.db.connection.cursor().execute('SELECT
InitSpatialMetaData(1);')";
}}}
Or a custom DatabaseWrapper which extends from the spatialite version:
{{{
from django.contrib.gis.db.backends.spatialite import base
class DatabaseWrapper(base.DatabaseWrapper):
def prepare_database(self):
# Workaround for https://code.djangoproject.com/ticket/32935
with self.cursor() as cursor:
cursor.execute("PRAGMA table_info(geometry_columns);")
if cursor.fetchall() == []:
cursor.execute("SELECT InitSpatialMetaData(1)")
super().prepare_database()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32935#comment:11>