Skip to content

Commit 10a8316

Browse files
Type: Fix modified check_ctor_args to pass default SRS_ID value in case of null (#488)
1 parent 4e4f45d commit 10a8316

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

geoalchemy2/types/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ def process(bindvalue):
179179
@staticmethod
180180
def check_ctor_args(geometry_type, srid, dimension, use_typmod, nullable):
181181
try:
182-
srid = int(srid)
183-
except ValueError:
182+
# passing default SRID if it is NULL from DB
183+
srid = int(srid if srid is not None else -1)
184+
except (ValueError, TypeError):
184185
raise ArgumentError("srid must be convertible to an integer")
185186
if geometry_type:
186187
geometry_type = geometry_type.upper()

tests/test_types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def test_get_col_spec(self):
4444
g = Geometry(srid=900913)
4545
assert g.get_col_spec() == "geometry(GEOMETRY,900913)"
4646

47+
def test_get_col_spec_no_srid(self):
48+
g = Geometry(srid=None)
49+
assert g.get_col_spec() == "geometry(GEOMETRY,-1)"
50+
51+
def test_get_col_spec_invalid_srid(self):
52+
with pytest.raises(ArgumentError) as e:
53+
g = Geometry(srid="foo")
54+
g.get_col_spec()
55+
assert str(e.value) == "srid must be convertible to an integer"
56+
4757
def test_get_col_spec_no_typmod(self):
4858
g = Geometry(geometry_type=None)
4959
assert g.get_col_spec() == "geometry"

0 commit comments

Comments
 (0)