Opened 13 years ago

Closed 13 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

Description

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:
        # 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 by adamfast, 13 years ago

Cc: adamfast added
Needs tests: set
Triage Stage: UnreviewedAccepted

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 by Aymeric Augustin, 13 years ago

Resolution: duplicate
Status: newclosed

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