Skip to content

Commit ed6ba60

Browse files
committed
fix: guard Db2EngineAdapter import on db2-sqlglot-dialect presence, not just Python version
1 parent d9acfc4 commit ed6ba60

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

sqlmesh/core/engine_adapter/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import importlib.util
34
import sys
45
import typing as t
56

@@ -23,8 +24,16 @@
2324
from sqlmesh.core.engine_adapter.risingwave import RisingwaveEngineAdapter
2425
from sqlmesh.core.engine_adapter.fabric import FabricEngineAdapter
2526

26-
# DB2 adapter requires Python 3.10+ for db2-sqlglot-dialect
27-
if sys.version_info >= (3, 10):
27+
# DB2 adapter requires Python 3.10+ AND db2-sqlglot-dialect to be installed.
28+
# The dialect package registers "db2" with sqlglot at import time; without it,
29+
# class-level exp.DataType.build(dialect="db2") in db2.py raises
30+
# ValueError("Unknown dialect 'db2'") and crashes every non-db2 environment
31+
# (e.g. the dbt-1.6 test run which installs without the db2 extra).
32+
_DB2_AVAILABLE = (
33+
sys.version_info >= (3, 10)
34+
and importlib.util.find_spec("db2_sqlglot") is not None
35+
)
36+
if _DB2_AVAILABLE:
2837
from sqlmesh.core.engine_adapter.db2 import Db2EngineAdapter
2938

3039
DIALECT_TO_ENGINE_ADAPTER = {
@@ -46,8 +55,8 @@
4655
"starrocks": StarRocksEngineAdapter,
4756
}
4857

49-
# Add DB2 only on Python 3.10+
50-
if sys.version_info >= (3, 10):
58+
# Add DB2 to the registry only when the dialect package is present
59+
if _DB2_AVAILABLE:
5160
DIALECT_TO_ENGINE_ADAPTER["db2"] = Db2EngineAdapter
5261

5362
DIALECT_ALIASES = {

0 commit comments

Comments
 (0)