Skip to content

Commit 24126f4

Browse files
committed
refactor(engine_adapter): add set_default_catalog instead of poking _default_catalog
Cleanup for expired environments needed to override a cloned adapter's default catalog, but with_settings() hardcodes default_catalog from the source adapter, leaving no public way to override it. Add a small setter instead of reaching into the private attribute directly. Signed-off-by: mday-io <mdaytn@gmail.com>
1 parent 271f280 commit 24126f4

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

sqlmesh/core/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,9 +3181,9 @@ def _cleanup_adapters_for_environment(
31813181
cleanup_adapter = engine_adapters.get(gateway, default_adapter).with_settings()
31823182
cleanup_adapter.inject_virtual_catalog(gateway)
31833183
# inject_virtual_catalog() may initialize adapter-specific state in addition to
3184-
# _default_catalog. Override only the cleanup clone with the catalog persisted in the
3185-
# expired environment so historical names pass SINGLE_CATALOG_ONLY validation.
3186-
cleanup_adapter._default_catalog = next(iter(catalogs))
3184+
# the default catalog. Override only the cleanup clone with the catalog persisted
3185+
# in the expired environment so historical names pass SINGLE_CATALOG_ONLY validation.
3186+
cleanup_adapter.set_default_catalog(next(iter(catalogs)))
31873187
cleanup_engine_adapters[gateway] = cleanup_adapter
31883188
if gateway == self.selected_gateway:
31893189
cleanup_default_adapter = cleanup_adapter

sqlmesh/core/engine_adapter/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ def default_catalog(self) -> t.Optional[str]:
295295
)
296296
return default_catalog
297297

298+
def set_default_catalog(self, catalog: t.Optional[str]) -> None:
299+
"""Override this adapter's default catalog.
300+
301+
Used e.g. by janitor cleanup to restore a historical catalog name on a
302+
cloned adapter when cleaning up an expired environment's virtual catalog.
303+
"""
304+
self._default_catalog = catalog
305+
298306
@property
299307
def engine_run_mode(self) -> EngineRunMode:
300308
return EngineRunMode.SINGLE_MODE_ENGINE

0 commit comments

Comments
 (0)