File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -422,7 +422,7 @@ def to_sqlmesh(self, context: DbtContext) -> Model:
422422 "target_lag" : self .target_lag ,
423423 }
424424
425- return create_sql_model (
425+ model = create_sql_model (
426426 self .canonical_name (context ),
427427 query ,
428428 dialect = model_dialect ,
@@ -431,6 +431,12 @@ def to_sqlmesh(self, context: DbtContext) -> Model:
431431 ** optional_kwargs ,
432432 ** model_kwargs ,
433433 )
434+ # Prepopulate the _full_depends_on cache with dependencies sourced directly from the manifest.
435+ # This ensures that we bypass query rendering that would otherwise be required to extract additional
436+ # dependencies from the model's SQL.
437+ # Note: any table dependencies that are not referenced using the `ref` macro will not be included.
438+ model ._full_depends_on = model .depends_on_
439+ return model
434440
435441 def _dbt_max_partition_blob (self ) -> t .Optional [str ]:
436442 """Returns a SQL blob which declares the _dbt_max_partition variable. Only applicable to BigQuery."""
Original file line number Diff line number Diff line change @@ -789,3 +789,22 @@ def test_variable_override():
789789 variables = {"yet_another_var" : 2 , "start" : "2021-01-01" },
790790 )
791791 assert project .packages ["sushi" ].variables ["yet_another_var" ] == 2
792+
793+
794+ def test_depends_on (assert_exp_eq , sushi_test_project ):
795+ # Case 1: using an undefined variable without a default value
796+ context = sushi_test_project .context
797+
798+ model_config = ModelConfig (
799+ alias = "sushi.test" ,
800+ sql = "SELECT * FROM {{ ref('waiter_revenue_by_day') }} JOIN other_table" ,
801+ dependencies = Dependencies (refs = ["waiter_revenue_by_day" ]),
802+ )
803+
804+ sqlmesh_model = model_config .to_sqlmesh (context )
805+ assert sqlmesh_model .depends_on_ == {'"memory"."sushi"."waiter_revenue_by_day_v2"' }
806+ assert sqlmesh_model .depends_on == {'"memory"."sushi"."waiter_revenue_by_day_v2"' }
807+ assert sqlmesh_model .full_depends_on == {'"memory"."sushi"."waiter_revenue_by_day_v2"' }
808+
809+ # Make sure the query wasn't rendered
810+ assert not sqlmesh_model ._query_renderer ._cache
You can’t perform that action at this time.
0 commit comments