Skip to content

Commit b20e5e9

Browse files
Fix: Use empty event for unsupported dialects (#421)
1 parent b3204da commit b20e5e9

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

geoalchemy2/__init__.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from geoalchemy2 import functions # noqa
99
from geoalchemy2 import types # noqa
10+
from geoalchemy2.dialects import common
1011
from geoalchemy2.dialects import postgresql
1112
from geoalchemy2.dialects import sqlite
1213
from geoalchemy2.dialects.common import _check_spatial_type
@@ -27,12 +28,7 @@ def _select_dialect(dialect_name):
2728
"postgresql": postgresql,
2829
"sqlite": sqlite,
2930
}
30-
try:
31-
return known_dialects[dialect_name]
32-
except KeyError:
33-
raise ValueError(
34-
f"The dialect '{dialect_name}' is unknown, please choose one of {known_dialects.keys()}"
35-
)
31+
return known_dialects.get(dialect_name, common)
3632

3733

3834
def _setup_ddl_event_listeners():

tests/test_functional.py

+34
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from sqlalchemy.testing.assertions import ComparesTables
3333

3434
import geoalchemy2
35+
import geoalchemy2.dialects
3536
from geoalchemy2 import Geography
3637
from geoalchemy2 import Geometry
3738
from geoalchemy2 import Raster
@@ -92,6 +93,39 @@ def test_no_geom_type(self, conn):
9293
# Drop the table
9394
t.drop(bind=conn)
9495

96+
@test_only_with_dialects("postgresql")
97+
def test_common_dialect(self, conn, monkeypatch, metadata, Lake):
98+
monkeypatch.setattr(conn.dialect, "name", "UNKNOWN DIALECT")
99+
100+
marks = []
101+
102+
def before_create(table, bind, **kw):
103+
marks.append("before_create")
104+
return
105+
106+
def after_create(table, bind, **kw):
107+
marks.append("after_create")
108+
return
109+
110+
def before_drop(table, bind, **kw):
111+
marks.append("before_drop")
112+
return
113+
114+
def after_drop(table, bind, **kw):
115+
marks.append("after_drop")
116+
return
117+
118+
monkeypatch.setattr(geoalchemy2.dialects.common, "before_create", value=before_create)
119+
monkeypatch.setattr(geoalchemy2.dialects.common, "after_create", value=after_create)
120+
monkeypatch.setattr(geoalchemy2.dialects.common, "before_drop", value=before_drop)
121+
monkeypatch.setattr(geoalchemy2.dialects.common, "after_drop", value=after_drop)
122+
123+
metadata.drop_all(conn, checkfirst=True)
124+
metadata.create_all(conn)
125+
metadata.drop_all(conn, checkfirst=True)
126+
127+
assert marks == ["before_create", "after_create", "before_drop", "after_drop"]
128+
95129

96130
class TestMiscellaneous:
97131
@test_only_with_dialects("sqlite")

0 commit comments

Comments
 (0)