Skip to content

Commit b20bd02

Browse files
authored
fix!: raise instead of warn on catalog mismatch (#3890)
1 parent 41265e0 commit b20bd02

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

sqlmesh/core/engine_adapter/shared.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sqlglot import exp
1212

1313
from sqlmesh.core.dialect import to_schema
14-
from sqlmesh.utils.errors import UnsupportedCatalogOperationError
14+
from sqlmesh.utils.errors import UnsupportedCatalogOperationError, SQLMeshError
1515
from sqlmesh.utils.pydantic import PydanticModel
1616

1717
if t.TYPE_CHECKING:
@@ -328,8 +328,8 @@ def internal_wrapper(*args: t.Any, **kwargs: t.Any) -> t.Any:
328328
container[key] = expression # type: ignore
329329
if catalog_support.is_single_catalog_only:
330330
if catalog_name != engine_adapter._default_catalog:
331-
logger.warning(
332-
f"{engine_adapter.dialect} requires that all catalog operations be against a single catalog: {engine_adapter._default_catalog}. Ignoring catalog: {catalog_name}"
331+
raise SQLMeshError(
332+
f"{engine_adapter.dialect} requires that all catalog operations be against a single catalog: {engine_adapter._default_catalog}. Provided catalog: {catalog_name}"
333333
)
334334
return func(*list_args, **kwargs)
335335
# Set the catalog name on the engine adapter if needed

tests/core/engine_adapter/integration/test_integration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from sqlmesh.core.snapshot import Snapshot, SnapshotChangeCategory
2929
from sqlmesh.utils.date import now, to_date, to_time_column
3030
from sqlmesh.core.table_diff import TableDiff
31+
from sqlmesh.utils.errors import SQLMeshError
3132
from sqlmesh.utils.pydantic import PydanticModel
3233
from tests.conftest import SushiDataValidator
3334
from tests.core.engine_adapter.integration import (
@@ -335,8 +336,11 @@ def create_objects_and_validate(schema_name: str):
335336

336337
schema = ctx.schema("drop_schema_catalog_test", catalog_name)
337338
if ctx.engine_adapter.catalog_support.is_single_catalog_only:
338-
drop_schema_and_validate(schema)
339-
assert "requires that all catalog operations be against a single catalog" in caplog.text
339+
with pytest.raises(
340+
SQLMeshError, match="requires that all catalog operations be against a single catalog"
341+
):
342+
drop_schema_and_validate(schema)
343+
create_objects_and_validate(schema)
340344
return
341345
drop_schema_and_validate(schema)
342346
create_objects_and_validate(schema)

tests/core/engine_adapter/test_postgres.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlglot.helper import ensure_list
88

99
from sqlmesh.core.engine_adapter import PostgresEngineAdapter
10+
from sqlmesh.utils.errors import SQLMeshError
1011
from tests.core.engine_adapter import to_sql_calls
1112

1213
pytestmark = [pytest.mark.engine, pytest.mark.postgres]
@@ -53,15 +54,15 @@ def test_drop_schema(kwargs, expected, make_mocked_engine_adapter: t.Callable):
5354
assert to_sql_calls(adapter) == ensure_list(expected)
5455

5556

56-
def test_drop_schema_with_catalog(
57-
make_mocked_engine_adapter: t.Callable, mocker: MockFixture, caplog
58-
):
57+
def test_drop_schema_with_catalog(make_mocked_engine_adapter: t.Callable, mocker: MockFixture):
5958
adapter = make_mocked_engine_adapter(PostgresEngineAdapter)
6059

6160
adapter.get_current_catalog = mocker.MagicMock(return_value="other_catalog")
6261

63-
adapter.drop_schema("test_catalog.test_schema")
64-
assert "requires that all catalog operations be against a single catalog" in caplog.text
62+
with pytest.raises(
63+
SQLMeshError, match="requires that all catalog operations be against a single catalog"
64+
):
65+
adapter.drop_schema("test_catalog.test_schema")
6566

6667

6768
def test_comments(make_mocked_engine_adapter: t.Callable, mocker: MockerFixture):

0 commit comments

Comments
 (0)