Opened 10 years ago

Closed 9 years ago

#17278 closed Cleanup/optimization (fixed)

Unlike sqlite, spatialite requires NAME to be set to run the tests

Reported by: Aymeric Augustin Owned by: nobody
Component: GIS Version:
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Attachments (2)

17278-1.diff (2.0 KB) - added by Ramiro Morales 10 years ago.
17278-spatialite-settings.diff (2.1 KB) - added by Julien Phalip 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

Changed 10 years ago by Ramiro Morales

Attachment: 17278-1.diff added

comment:2 Changed 10 years ago by Ramiro Morales

Has patch: set

This happens because SpatiaLite backend's DatabaseOperations tries to query and verify the version of the SpatiaLite library in its __init__() method.

This must be done with a SELECT query (hence, a cursor and a connection to the database are needed). For this, it creates disposable connection+cursor well before DatabaseWrapper creates the main, 'official' connection (remember that DatabaseOperations instance self.ops is instantiated in DatabaseWrapper.__init__()). This works because, even when the interface is a SELECT SQL query, no actual database is needed to query for the SpatiaLite library version.

All this doesn't cause problems with a normal project/application setup because there settings.DATABASES['whatever']['NAME'] are expected to have valid values.

Problem occurs with the test database setup with no settings.DATABASES['whatever']['NAME'] because in that scenario, when DatabaseWrapper.__init__() gets executed, the test DB creation machinery from django.contrib.gis.db.backends.spatialite.creation hasn't had a chance to run yet and so the database name hasn't been set to the fallback ':memory:' value.

The attached patch moves the SpatiaLite version querying/checking tasks to a separate internal method and inserts a call to it right after the connection to the database and SpatiaLite initialization have been performed.

Last edited 10 years ago by Ramiro Morales (previous) (diff)

comment:3 Changed 10 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

Looks good

Changed 9 years ago by Julien Phalip

comment:4 Changed 9 years ago by Julien Phalip

Triage Stage: Ready for checkinAccepted

I've updated the patch to avoid a problem with the 'spatial_version' variable not being set at the right time.

comment:5 Changed 9 years ago by Julien Phalip <jphalip@…>

Resolution: fixed
Status: newclosed

In [675431dfaaa7fc9fbd89be2602332287489ee04f]:

Fixed #17278 -- Enabled the spatialite GIS tests to run without having to specify a database name in the settings. Thanks to Aymeric for the report and to Ramiro for the initial patch.

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