Opened 13 years ago
Closed 12 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)
Change History (7)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 13 years ago
Attachment: | 17278-1.diff added |
---|
by , 12 years ago
Attachment: | 17278-spatialite-settings.diff added |
---|
comment:4 by , 12 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
I've updated the patch to avoid a problem with the 'spatial_version' variable not being set at the right time.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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, whenDatabaseWrapper.__init__()
gets executed, the test DB creation machinery fromdjango.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.