Skip to content

Commit 3d28450

Browse files
committed
Fix: Handle case where partition_by is explicitly passed in as None to dbt ModelConfig
1 parent a7feeb7 commit 3d28450

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

sqlmesh/dbt/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ def _validate_sql(cls, v: t.Union[str, SqlStr]) -> SqlStr:
154154

155155
@field_validator("partition_by", mode="before")
156156
@classmethod
157-
def _validate_partition_by(cls, v: t.Any) -> t.Union[t.List[str], t.Dict[str, t.Any]]:
157+
def _validate_partition_by(
158+
cls, v: t.Any
159+
) -> t.Optional[t.Union[t.List[str], t.Dict[str, t.Any]]]:
160+
if v is None:
161+
return None
158162
if isinstance(v, str):
159163
return [v]
160164
if isinstance(v, list):

tests/dbt/test_transformation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,23 @@ def test_partition_by(sushi_test_project: Project):
13291329
assert model_config.to_sqlmesh(context).partitioned_by == [exp.to_column("ds", quoted=True)]
13301330

13311331

1332+
@pytest.mark.xdist_group("dbt_manifest")
1333+
def test_partition_by_none(sushi_test_project: Project):
1334+
context = sushi_test_project.context
1335+
context.target = BigQueryConfig(name="production", database="main", schema="sushi")
1336+
model_config = ModelConfig(
1337+
name="model",
1338+
alias="model",
1339+
schema="test",
1340+
package_name="package",
1341+
materialized="table",
1342+
unique_key="ds",
1343+
partition_by=None,
1344+
sql="""SELECT 1 AS one, ds FROM foo""",
1345+
)
1346+
assert model_config.partition_by is None
1347+
1348+
13321349
@pytest.mark.xdist_group("dbt_manifest")
13331350
def test_relation_info_to_relation():
13341351
assert _relation_info_to_relation(

0 commit comments

Comments
 (0)