layermapping spatial ref check not checking against alternate DB
Reported by: |
shifflett.shane@… |
Owned by: |
jbronn |
Component:
|
GIS
|
Version:
|
1.3
|
Severity:
|
Release blocker
|
Keywords:
|
|
Cc:
|
|
Triage Stage:
|
Accepted
|
Has patch:
|
yes
|
Needs documentation:
|
no
|
Needs tests:
|
no
|
Patch needs improvement:
|
no
|
Easy pickings:
|
no
|
UI/UX:
|
no
|
django/contrib/gis/utils/layermapping.py uses alternate database to save geometries however when checking the SRID against the SPATIAL REF table it does not check against an alternate database if the user specifies one. For a user to experience this error they must have two databases and the default database cannot store shape data.
issue occurs in django/contrib/gis/utils/layermapping.py line 432
OLD CODE (SRID lookup will fail if user has an alternate database storing shape data):
target_srs = SpatialRefSys.objects.get(srid=self.geo_field.srid).srs
PROPOSED FIX (SRID lookup succeeds and functions similar to SAVE function):
target_srs = SpatialRefSys.objects.using(self.using).get(srid=self.geo_field.srid).srs
This line dates back to the merge of multi-db at r11952, but it was changed because of the general refactoring of django.contrib.gis that happened in that commit, not specifically to add multi-db support.
A similar problem was fixed in django/contrib/gis/db/models/fields.py at r12258.
I think the problem also happens in django/contrib/gis/utils/srs.py. I'm attaching a new patch that also fixes this. This patch is based on code inspection and isn't tested.