Opened 9 years ago

Closed 9 years ago

#11867 closed (fixed)

if spatialite is installed and pysqlite2.5 is installed without `enable_load_extension` tests won't run

Reported by: Daniel Ring Owned by: nobody
Component: GIS Version: 1.1
Severity: Keywords: enable_load_extension
Cc: Daniel Ring Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Using spatialite with contrib.gis is supported only with pysqlite2.5.0 or higher, and pysqlite must be compiled with enable_load_extension support (see ). If spatialite is present, settings.DATABASE_ENGINE == 'sqlite3', and pysqlite is present but without enable_load_extension support, tests/ fails as follows:

Traceback (most recent call last):
  File "./", line 191, in <module>
    django_tests(int(options.verbosity), options.interactive, args)
  File "./", line 161, in django_tests
    failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
  File "/home/dan/work/django/django/django/test/", line 191, in run_tests
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
  File "/home/dan/work/django/django/django/db/backends/", line 332, in create_test_db
    can_rollback = self._rollback_works()
  File "/home/dan/work/django/django/django/db/backends/", line 389, in _rollback_works
    cursor = self.connection.cursor()
  File "/home/dan/work/django/django/django/db/backends/", line 81, in cursor
    cursor = self._cursor()
  File "/home/dan/work/django/django/django/db/backends/sqlite3/", line 175, in _cursor
  File "/home/dan/work/django/django/django/dispatch/", line 166, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/dan/work/django/django/django/contrib/gis/db/backend/spatialite/", line 26, in initialize_spatialite
AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

Note that this is not a test failure, but rather a failure of any tests to run at all.

Also, Debian package python-pysqlite2 (currently) defaults to disabling enable_load_extension. (See: )

I think either

  1. settings.DATABASE_ENGINE='spatialite' instead of 'sqlite3' should be used (my preference) (or maybe sqlite3_spatialite or something); or
  1. contrib.gis.tests.utils.spatialite should only be set if enable_load_extension is available (contrib.gis tests should be skipped somehow).

Change History (1)

comment:1 Changed 9 years ago by jbronn

Resolution: fixed
Status: newclosed

This was fixed in trunk when multi-db was merged in. In order to support multiple databases, the spatial backends became full-fledged Django database backends. An example configuration:

    'default' : {
        'ENGINE' : 'django.contrib.gis.db.backends.spatialite',
        'NAME'   : 'geodjango.db',

Thus, your request for a spatialite backend was fulfilled. If still using the old DATABASE_* settings, then DATABASE_ENGINE='sqlite3' may still be used but 'django.contrib.gis' must also be in your INSTALLED_APPS to enable backwards-compatibility.

Also trunk now has better error-handling in absence of enable_load_extension. Specifically, the spatialite backend, upon initialization, now explicitly checks for support and raises a clear error on what went wrong:

# Enabling extension loading on the SQLite connection.
except AttributeError:
    raise ImproperlyConfigured('The pysqlite library does not support C extension loading. '
                               'Both SQLite and pysqlite must be configured to allow '
                               'the loading of extensions to use SpatiaLite.'

(from [browser:django/trunk/django/contrib/gis/db/backends/spatialite/])

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