Opened 4 years ago

Closed 4 years ago

#16620 closed Bug (duplicate)

django.contrib.gis.utils.srs.add_srs_entry doesn't use the database parameter

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


When using add_srs_entry like add_srs_entry(900913, database="gis"), it still goes to default database. Correct should be

    # Creating the spatial_ref_sys model.
        # Try getting via SRID only, because using all kwargs may
        # differ from exact wkt/proj in database.
        sr = SpatialRefSys.objects.using(database).get(srid=srs.srid)
    except SpatialRefSys.DoesNotExist:
        sr = SpatialRefSys.objects.using(database).create(**kwargs)

Change History (2)

comment:1 Changed 4 years ago by adamfast

  • Cc adamfast added
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

More background: user has a non-spatial primary database (MySQL) and is using spatialite as a secondary database (named gis) for GIS data. When attempting to run add_srs_entry() GeoDjango is attempting to create the record on his (default) MySQL db which errors since there is no SRS capability in that backend.

Confirmed as an issue. In this code SpatialRefSys is pulled from connection.ops.spatial_ref_sys() (connection being the proper connection for the database alias passed in) but the implementation in the backend is to simply import and return the model from the backend and not pass on which database alias is to be used so running .get or .create uses the default DB and not the one passed in. A using() here is probably the right solution.

comment:2 Changed 4 years ago by aaugustin

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

Duplicate of #16537 and #16556 — please do a little search before reporting or accepting new issues.

It would be really useful to add tests to the patch attached to #16537 and review it.

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