Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type: Fix Modified check_ctor_args to pass default SRS_ID value in case of null #488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions geoalchemy2/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ def process(bindvalue):
@staticmethod
def check_ctor_args(geometry_type, srid, dimension, use_typmod, nullable):
try:
srid = int(srid)
except ValueError:
# passing default SRID if it is NULL from DB
srid = int(srid if srid is not None else -1)
except (ValueError, TypeError):
raise ArgumentError("srid must be convertible to an integer")
if geometry_type:
geometry_type = geometry_type.upper()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def test_get_col_spec(self):
g = Geometry(srid=900913)
assert g.get_col_spec() == "geometry(GEOMETRY,900913)"

def test_get_col_spec_no_srid(self):
g = Geometry(srid=None)
assert g.get_col_spec() == "geometry(GEOMETRY,-1)"

def test_get_col_spec_invalid_srid(self):
with pytest.raises(ArgumentError) as e:
g = Geometry(srid="foo")
g.get_col_spec()
assert str(e.value) == "srid must be convertible to an integer"

def test_get_col_spec_no_typmod(self):
g = Geometry(geometry_type=None)
assert g.get_col_spec() == "geometry"
Expand Down