Skip to content

fix: prevent default catalog leak into catalog-unsupported gateways#5750

Closed
brucearctor wants to merge 1 commit intoSQLMesh:mainfrom
brucearctor:fix/default-catalog-leak-5748
Closed

fix: prevent default catalog leak into catalog-unsupported gateways#5750
brucearctor wants to merge 1 commit intoSQLMesh:mainfrom
brucearctor:fix/default-catalog-leak-5748

Conversation

@brucearctor
Copy link
Copy Markdown

Description

Fixes #5748.

When a multi-gateway SQLMesh project uses a default gateway with a catalog (e.g., Trino with catalog: example_catalog), that catalog is silently prepended to model names targeting secondary gateways that do not support catalogs (e.g., ClickHouse), causing UnsupportedCatalogOperationError at evaluation time.

Root cause: The per-gateway catalog dict (default_catalog_per_gateway) is built in BuiltInSchedulerConfig.get_default_catalog_per_gateway(). Catalog-unsupported adapters return None for default_catalog and are never added to the dict. The model loader in create_models_from_blueprints() then cannot distinguish "this gateway has no catalog" from "this gateway was not checked", so the global default_catalog leaks through.

Fix: Explicitly register catalog-unsupported gateways with empty string ("") in the per-gateway dict. The model loader's existing is not None check picks up the empty string and overrides default_catalog to "", which does not get prepended to the model name.

Changes

File Change
sqlmesh/core/config/scheduler.py Added elif branch to register catalog-unsupported gateways with ""
tests/core/test_model.py Added regression test test_default_catalog_not_leaked_to_unsupported_gateway

Test Plan

  • Added test_default_catalog_not_leaked_to_unsupported_gateway regression test that verifies:
    • With "" in default_catalog_per_gatewayexample_catalog does not leak into the model FQN
    • Without the entry for the gateway → example_catalog does leak (confirming the bug behavior)
  • All existing gateway-related tests pass: test_gateway_macro, test_gateway_macro_jinja, test_gateway_python_model, test_gateway_specific_render, test_model_cache_gateway
  • ruff and ruff-format pass
  • mypy passes on changed file (pre-existing unrelated error in gateway.py)

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

…QLMesh#5748)

When a multi-gateway project uses a default gateway with a catalog
(e.g. Trino), that catalog was silently prepended to model names
targeting secondary gateways that don't support catalogs (e.g.
ClickHouse), causing UnsupportedCatalogOperationError at evaluation.

Root cause: catalog-unsupported adapters return None for
default_catalog and are never added to default_catalog_per_gateway.
The model loader cannot distinguish 'no catalog' from 'not checked',
so the global default_catalog leaks through.

Fix: explicitly register catalog-unsupported gateways with empty
string in the per-gateway dict. The model loader's 'is not None'
check picks this up and overrides default_catalog to '', preventing
the leak.

Signed-off-by: Bruce Arctor <brucearctor@users.noreply.github.com>
for gateway, adapter in context.engine_adapters.items():
if catalog := adapter.default_catalog:
default_catalogs_per_gateway[gateway] = catalog
elif adapter.catalog_support.is_unsupported:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will leak the empty string "" into downstream operations as actual catalog value. None is already the representation for no catalog in most code paths, so the fix should be in definition.py instead, so take a look and adapt it to be similar to the option b suggested in the original issue

@themisvaltinos
Copy link
Copy Markdown
Collaborator

fixed here: #5752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Default gateway catalog leaks into catalog-unsupported secondary gateways

2 participants