@@ -8845,6 +8845,54 @@ def entrypoint(context, *args, **kwargs):
88458845 assert t .cast (pd .DataFrame , list (m .render (context = context ))[0 ]).to_dict () == {"x" : {0 : 1 }}
88468846
88478847
8848+ def test_python_model_depends_on_blueprints (tmp_path : Path ) -> None :
8849+ sql_model = tmp_path / "models" / "base_blueprints.sql"
8850+ sql_model .parent .mkdir (parents = True , exist_ok = True )
8851+ sql_model .write_text (
8852+ """
8853+ MODEL (
8854+ name test_schema1.@{model_name},
8855+ blueprints ((model_name := foo), (model_name := bar)),
8856+ kind FULL
8857+ );
8858+
8859+ SELECT 1 AS id
8860+ """
8861+ )
8862+
8863+ py_model = tmp_path / "models" / "depends_on_with_blueprint_vars.py"
8864+ py_model .parent .mkdir (parents = True , exist_ok = True )
8865+ py_model .write_text (
8866+ """
8867+ import pandas as pd
8868+ from sqlmesh import model
8869+
8870+ @model(
8871+ "test_schema2.@model_name",
8872+ columns={
8873+ "id": "int",
8874+ },
8875+ blueprints=[
8876+ {"model_name": "foo"},
8877+ {"model_name": "bar"},
8878+ ],
8879+ depends_on=["test_schema1.@{model_name}"],
8880+ )
8881+ def entrypoint(context, *args, **kwargs):
8882+ table = context.resolve_table(f"test_schema1.{context.blueprint_var('model_name')}")
8883+ return context.fetchdf(f"SELECT * FROM {table}")"""
8884+ )
8885+
8886+ ctx = Context (
8887+ config = Config (model_defaults = ModelDefaultsConfig (dialect = "duckdb" )),
8888+ paths = tmp_path ,
8889+ )
8890+ assert len (ctx .models ) == 4
8891+
8892+ ctx .plan (no_prompts = True , auto_apply = True )
8893+ assert ctx .fetchdf ("SELECT * FROM test_schema2.foo" ).to_dict () == {"id" : {0 : 1 }}
8894+
8895+
88488896@time_machine .travel ("2020-01-01 00:00:00 UTC" )
88498897def test_dynamic_date_spine_model (assert_exp_eq ):
88508898 @macro ()
0 commit comments