The problem I’m having
I’m trying to understand the exact timing of macro expansion during dbt run, especially in scenarios where the run_query macro is used to reference dependencies. Specifically, I want to know if dbt expands macros for all models first before executing them in dependency order, or if it expands and executes each model sequentially according to dependencies.
The context of why I’m trying to do this
In my project, I use the run_query macro within model B to reference data in model A, which B depends on. The timing of macro expansion and execution is crucial to ensure that A is fully built and its data is available before B attempts to reference it via run_query. Understanding whether dbt run builds (expands macros) for all models first or if it does so model-by-model would help me avoid issues where the query might fail or produce unexpected results.
What I’ve already tried
I’ve looked through dbt’s documentation and various community posts, but I haven’t found a clear answer.