Skip to content

Commit 1b2979b

Browse files
authored
Fix: Variable overrides for dbt packages (#5376)
1 parent 745db0f commit 1b2979b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

sqlmesh/dbt/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def load(cls, context: DbtContext, variables: t.Optional[t.Dict[str, t.Any]] = N
113113
package.variables.update(package_scoped_vars)
114114
else:
115115
package.variables.update(all_project_variables)
116+
if variable_overrides:
117+
package.variables.update(variable_overrides)
116118

117119
return Project(context, profile, packages)
118120

tests/dbt/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ def test_variables(assert_exp_eq, sushi_test_project):
367367
assert sushi_test_project.packages["customers"].variables == expected_customer_variables
368368

369369

370+
@pytest.mark.slow
371+
def test_variables_override(init_and_plan_context: t.Callable):
372+
context, _ = init_and_plan_context(
373+
"tests/fixtures/dbt/sushi_test", config="test_config_with_var_override"
374+
)
375+
dbt_project = context._loaders[0]._load_projects()[0] # type: ignore
376+
assert dbt_project.packages["sushi"].variables["some_var"] == "overridden_from_config_py"
377+
assert dbt_project.packages["customers"].variables["some_var"] == "overridden_from_config_py"
378+
379+
370380
@pytest.mark.slow
371381
def test_jinja_in_dbt_variables(sushi_test_dbt_context: Context):
372382
assert sushi_test_dbt_context.render("sushi.top_waiters").sql().endswith("LIMIT 10")

tests/fixtures/dbt/sushi_test/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111

1212
test_config = config
1313

14+
15+
test_config_with_var_override = sqlmesh_config(
16+
Path(__file__).parent,
17+
model_defaults=ModelDefaultsConfig(dialect="duckdb", start="Jan 1 2022"),
18+
variables={
19+
"some_var": "overridden_from_config_py",
20+
},
21+
)
22+
23+
1424
test_config_with_normalization_strategy = sqlmesh_config(
1525
Path(__file__).parent,
1626
model_defaults=ModelDefaultsConfig(

0 commit comments

Comments
 (0)