Skip to content

Commit 9d6d9e7

Browse files
committed
Fix get_current_catalog() to return lowercase — unblock 6 ctx.create_context() tests
CURRENT SERVER returns 'TESTDB' from Db2. The DuckDB-dialect config parser uses LOWERCASE normalisation and lowercases all identifiers, so _default_catalog is 'testdb'. The previous .upper() call made get_current_catalog() return 'TESTDB', which failed the raw == comparison in shared.py:346 and raised SQLMeshError in every test that calls ctx.create_context(). Fix: return result[0].lower() — same as Postgres, Redshift, and MySQL. The set_catalog decorator strips the catalog from all DDL before sending it to Db2, so the case of this value never affects SQL sent to the engine. Remove the 6 db2 pytest.skip blocks that were guarding these tests: - test_batch_size_on_incremental_by_unique_key_model - test_incremental_by_unique_key_model_when_matched - test_state_migrate_from_scratch - test_python_model_column_order - test_unicode_characters - test_grants_plan Update test_get_current_catalog: assert result == 'testdb' (was 'TESTDB').
1 parent 28047bf commit 9d6d9e7

3 files changed

Lines changed: 12 additions & 49 deletions

File tree

‎sqlmesh/core/engine_adapter/db2.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,16 @@ class Db2EngineAdapter(
8888
def get_current_catalog(self) -> t.Optional[str]:
8989
"""
9090
Db2 requires FROM SYSIBM.SYSDUMMY1 to read the CURRENT SERVER special register.
91-
Returns uppercase to match the Db2 dialect's identifier normalisation.
91+
Returns lowercase so _default_catalog matches the catalog name produced by the
92+
DuckDB-dialect config parser (which lowercases all identifiers via LOWERCASE
93+
normalisation strategy). The set_catalog decorator always strips the catalog
94+
from DDL before execution, so the case of this value never affects SQL sent to
95+
Db2. Every other SINGLE_CATALOG_ONLY engine (Postgres, Redshift, MySQL) also
96+
returns lowercase — this follows the same pattern.
9297
"""
9398
result = self.fetchone("SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1")
9499
if result:
95-
return result[0].upper() if result[0] else None
100+
return result[0].lower() if result[0] else None
96101
return None
97102

98103
def _build_schema_exp(

‎tests/core/engine_adapter/integration/test_integration.py‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,15 +2744,6 @@ def test_to_time_column(
27442744

27452745

27462746
def test_batch_size_on_incremental_by_unique_key_model(ctx: TestContext):
2747-
if ctx.dialect == "db2":
2748-
pytest.skip(
2749-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
2750-
"(shared.py:346). This test creates a SQLMesh context whose default_dialect "
2751-
"is 'duckdb', which lowercases catalog names ('testdb'). That does not match "
2752-
"_default_catalog 'TESTDB' and raises SQLMeshError. Fix requires either "
2753-
"case-insensitive catalog comparison in the framework or switching to "
2754-
"REQUIRES_SET_CATALOG with a no-op set_current_catalog — tracked separately."
2755-
)
27562747
if not ctx.supports_merge:
27572748
pytest.skip(f"{ctx.dialect} on {ctx.gateway} doesnt support merge")
27582749

@@ -2849,13 +2840,6 @@ def _mutate_config(current_gateway_name: str, config: Config):
28492840

28502841

28512842
def test_incremental_by_unique_key_model_when_matched(ctx: TestContext):
2852-
if ctx.dialect == "db2":
2853-
pytest.skip(
2854-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
2855-
"(shared.py:346). ctx.create_context() produces a duckdb-dialect context "
2856-
"which lowercases catalog names ('testdb'), not matching _default_catalog "
2857-
"'TESTDB'. Fix: switch to REQUIRES_SET_CATALOG with no-op set_current_catalog."
2858-
)
28592843
if not ctx.supports_merge:
28602844
pytest.skip(f"{ctx.dialect} on {ctx.gateway} doesnt support merge")
28612845

@@ -3582,13 +3566,6 @@ def test_table_diff_identical_dataset(ctx: TestContext):
35823566

35833567

35843568
def test_state_migrate_from_scratch(ctx: TestContext):
3585-
if ctx.dialect == "db2":
3586-
pytest.skip(
3587-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
3588-
"(shared.py:346). ctx.create_context() produces a duckdb-dialect context "
3589-
"which lowercases catalog names ('testdb'), not matching _default_catalog "
3590-
"'TESTDB'. Fix: switch to REQUIRES_SET_CATALOG with no-op set_current_catalog."
3591-
)
35923569
test_schema = ctx.add_test_suffix("state")
35933570
ctx._schemas.append(test_schema) # so it gets cleaned up when the test finishes
35943571

@@ -3623,14 +3600,6 @@ def _use_warehouse_as_state_connection(gateway_name: str, config: Config):
36233600

36243601
def test_python_model_column_order(ctx_df: TestContext, tmp_path: pathlib.Path):
36253602
ctx = ctx_df
3626-
if ctx.dialect == "db2":
3627-
pytest.skip(
3628-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
3629-
"(shared.py:346). ctx.create_context() produces a duckdb-dialect context "
3630-
"which lowercases catalog names ('testdb'), not matching _default_catalog "
3631-
"'TESTDB'. Fix: switch to REQUIRES_SET_CATALOG with no-op set_current_catalog."
3632-
)
3633-
36343603
model_name = ctx.table("TEST")
36353604

36363605
(tmp_path / "models").mkdir()
@@ -3998,13 +3967,6 @@ def _assert_mview_value(value: int):
39983967

39993968

40003969
def test_unicode_characters(ctx: TestContext, tmp_path: Path):
4001-
if ctx.dialect == "db2":
4002-
pytest.skip(
4003-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
4004-
"(shared.py:346). ctx.create_context() produces a duckdb-dialect context "
4005-
"which lowercases catalog names ('testdb'), not matching _default_catalog "
4006-
"'TESTDB'. Fix: switch to REQUIRES_SET_CATALOG with no-op set_current_catalog."
4007-
)
40083970
# Engines that don't quote identifiers in views are incompatible with unicode characters in model names
40093971
# at the time of writing this is Spark/Trino and they do this for compatibility reasons.
40103972
# I also think Spark may not support unicode in general but that would need to be verified.
@@ -4146,13 +4108,6 @@ def test_grants_case_insensitive_grantees(ctx: TestContext):
41464108

41474109

41484110
def test_grants_plan(ctx: TestContext, tmp_path: Path):
4149-
if ctx.dialect == "db2":
4150-
pytest.skip(
4151-
"Db2 SINGLE_CATALOG_ONLY uses a raw == comparison against _default_catalog "
4152-
"(shared.py:346). ctx.create_context() produces a duckdb-dialect context "
4153-
"which lowercases catalog names ('testdb'), not matching _default_catalog "
4154-
"'TESTDB'. Fix: switch to REQUIRES_SET_CATALOG with no-op set_current_catalog."
4155-
)
41564111
if not ctx.engine_adapter.SUPPORTS_GRANTS:
41574112
pytest.skip(
41584113
f"Skipping Test since engine adapter {ctx.engine_adapter.dialect} doesn't support grants"

‎tests/core/engine_adapter/test_db2.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,15 @@ def test_merge_alias_replacement(adapter: Db2EngineAdapter):
374374

375375

376376
def test_get_current_catalog(adapter: Db2EngineAdapter):
377-
"""get_current_catalog reads CURRENT SERVER from SYSIBM.SYSDUMMY1 and returns uppercase."""
377+
"""get_current_catalog reads CURRENT SERVER from SYSIBM.SYSDUMMY1 and returns lowercase.
378+
Lowercase is required so _default_catalog matches the catalog name produced by the
379+
DuckDB-dialect config parser, which lowercases all identifiers.
380+
"""
378381
adapter.cursor.fetchone.return_value = ("TESTDB",)
379382

380383
result = adapter.get_current_catalog()
381384

382-
assert result == "TESTDB"
385+
assert result == "testdb"
383386
# Raw string because fetchone is called with a plain string, not an exp.Expr
384387
assert to_sql_calls(adapter) == ["SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1"]
385388

0 commit comments

Comments
 (0)