Code

Opened 3 years ago

Closed 23 months ago

#17278 closed Cleanup/optimization (fixed)

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

Reported by: aaugustin 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 2 years ago.
17278-spatialite-settings.diff (2.1 KB) - added by julien 23 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Changed 2 years ago by ramiro

comment:2 Changed 2 years ago by ramiro

  • 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 2 years ago by ramiro (previous) (diff)

comment:3 Changed 2 years ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

Looks good

Changed 23 months ago by julien

comment:4 Changed 23 months ago by julien

  • Triage Stage changed from Ready for checkin to Accepted

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

comment:5 Changed 23 months ago by Julien Phalip <jphalip@…>

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.