Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqlmesh/dbt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ def to_sqlmesh(
self.name,
"views" if isinstance(kind, ViewKind) else "ephemeral models",
)
elif context.target.dialect == "snowflake":
logger.warning(
"Ignoring partition_by config for model '%s' targeting %s. The partition_by config is not supported for Snowflake.",
self.name,
context.target.dialect,
)
else:
partitioned_by = []
if isinstance(self.partition_by, list):
Expand Down
37 changes: 12 additions & 25 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
import logging
import os
import pytest
import string
import time_machine
from contextlib import contextmanager
from os import getcwd, path, remove
from pathlib import Path
from shutil import rmtree
Expand Down Expand Up @@ -35,15 +33,6 @@ def runner() -> CliRunner:
return CliRunner(env={"COLUMNS": "80"})


@contextmanager
def disable_logging():
logging.disable(logging.CRITICAL)
try:
yield
finally:
logging.disable(logging.NOTSET)


def create_example_project(temp_dir, template=ProjectTemplate.DEFAULT) -> None:
"""
Sets up CLI tests requiring a real SQLMesh project by:
Expand Down Expand Up @@ -795,8 +784,7 @@ def test_run_cron_not_elapsed(runner, tmp_path, caplog):
init_prod_and_backfill(runner, tmp_path)

# No error if `prod` environment exists and cron has not elapsed
with disable_logging():
result = runner.invoke(cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "run"])
result = runner.invoke(cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "run"])
assert result.exit_code == 0

assert (
Expand Down Expand Up @@ -843,18 +831,17 @@ def test_table_name(runner, tmp_path):
# Create and backfill `prod` environment
create_example_project(tmp_path)
init_prod_and_backfill(runner, tmp_path)
with disable_logging():
result = runner.invoke(
cli,
[
"--log-file-dir",
tmp_path,
"--paths",
tmp_path,
"table_name",
"sqlmesh_example.full_model",
],
)
result = runner.invoke(
cli,
[
"--log-file-dir",
tmp_path,
"--paths",
tmp_path,
"table_name",
"sqlmesh_example.full_model",
],
)
assert result.exit_code == 0
assert result.output.startswith("db.sqlmesh__sqlmesh_example.sqlmesh_example__full_model__")

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def rescope_duckdb_classvar(request):
yield


@pytest.fixture(scope="module", autouse=True)
@pytest.fixture(scope="function", autouse=True)
def rescope_log_handlers():
logging.getLogger().handlers.clear()
yield
Expand Down
9 changes: 7 additions & 2 deletions tests/dbt/test_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import datetime
import logging

import pytest

from pathlib import Path
Expand Down Expand Up @@ -274,7 +276,9 @@ def test_load_invalid_ref_audit_constraints(
with open(model_schema_file, "w", encoding="utf-8") as f:
yaml.dump(model_schema, f)

context = Context(paths=project_dir)
assert isinstance(get_console(), NoopConsole)
with caplog.at_level(logging.DEBUG):
context = Context(paths=project_dir)
assert (
"Skipping audit 'relationships_full_model_cola__cola__ref_not_real_model_' because model 'not_real_model' is not a valid ref"
in caplog.text
Expand Down Expand Up @@ -539,7 +543,8 @@ def test_load_deprecated_incremental_time_column(

snapshot_fqn = '"local"."main"."incremental_time_range"'
assert isinstance(get_console(), NoopConsole)
context = Context(paths=project_dir)
with caplog.at_level(logging.DEBUG):
context = Context(paths=project_dir)
model = context.snapshots[snapshot_fqn].model
# Validate model-level attributes
assert to_ds(model.start or "") == "2025-01-01"
Expand Down
11 changes: 10 additions & 1 deletion tests/dbt/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ def test_parsetime_adapter_call(


@pytest.mark.xdist_group("dbt_manifest")
def test_partition_by(sushi_test_project: Project):
def test_partition_by(sushi_test_project: Project, caplog):
context = sushi_test_project.context
context.target = BigQueryConfig(name="production", database="main", schema="sushi")
model_config = ModelConfig(
Expand Down Expand Up @@ -1928,6 +1928,15 @@ def test_partition_by(sushi_test_project: Project):
context.target = DuckDbConfig(name="target", schema="foo")
assert model_config.to_sqlmesh(context).partitioned_by == []

context.target = SnowflakeConfig(
name="target", schema="test", database="test", account="foo", user="bar", password="baz"
)
assert model_config.to_sqlmesh(context).partitioned_by == []
assert (
"Ignoring partition_by config for model 'model' targeting snowflake. The partition_by config is not supported for Snowflake."
in caplog.text
)

model_config = ModelConfig(
name="model",
alias="model",
Expand Down