Skip to content

Commit 7a2f1e7

Browse files
authored
fix: have python depends_on actually override (#1628)
1 parent 7af9406 commit 7a2f1e7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ def create_python_model(
17261726
depends_on = (
17271727
_parse_depends_on(entrypoint, python_env) - {name}
17281728
if depends_on is None and python_env is not None
1729-
else None
1729+
else depends_on
17301730
)
17311731
return _create_model(
17321732
PythonModel,

tests/core/test_model.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,24 @@ def my_model(context, **kwargs):
13031303
)
13041304

13051305

1306+
def test_python_model_depends_on() -> None:
1307+
@model(
1308+
name="model_with_depends_on", kind="full", columns={'"COL"': "int"}, depends_on=["foo.bar"]
1309+
)
1310+
def my_model(context, **kwargs):
1311+
context.table("foo")
1312+
context.table(model_name=CONST + ".baz")
1313+
1314+
m = model.get_registry()["model_with_depends_on"].model(
1315+
module_path=Path("."),
1316+
path=Path("."),
1317+
)
1318+
1319+
# We are not expecting the context.table() calls to be reflected in the model's depends_on since we
1320+
# explicitly specified the depends_on argument.
1321+
assert m.depends_on == {"foo.bar"}
1322+
1323+
13061324
def test_python_models_returning_sql(assert_exp_eq) -> None:
13071325
config = Config(model_defaults=ModelDefaultsConfig(dialect="snowflake"))
13081326
context = Context(config=config)

0 commit comments

Comments
 (0)