Modelling correctness · rule staging-depends-on-downstream
dbt staging models that read marts
A Metacenta review checks this under the rule Staging models do not read transformed models. Everything below applies whether or not you ever commission one.
What this rule checks
This rule flags staging models that read a model from the intermediate or marts layer. We place models in layers by the folders in their path. If no model's path places it in a layer, the rule declines.
Why it matters
Data flows backwards through the project, so the DAG no longer matches the layering the folders claim. A reader who trusts the folders will get the build order wrong.
How to fix it
Keep the first cleaning step off transformed data. Move the model into the layer its dependencies put it in, or break the backwards edge so it reads only its source.
Before:
-- models/staging/shop/stg_shop__refunds.sql
select r.*, o.customer_id
from {{ source('shop', 'refunds') }} as r
join {{ ref('fct_orders') }} as o using (order_id)
After:
-- models/marts/fct_refunds.sql
select r.*, o.customer_id
from {{ ref('stg_shop__refunds') }} as r
join {{ ref('fct_orders') }} as o using (order_id)
When it is fine to leave
Rarely. It is usually a model in the wrong folder, and moving it is the fix. The one fair case is a short window while a file is mid-move to its correct directory.
What we need to check it
manifest.json alone. Layers come from folder names in each model's path, so a model filed in the wrong folder is judged by where it sits.
Published rules it corresponds to
dbt_project_evaluator, rule fct_staging_dependent_on_marts_or_intermediate. Ours checks the same condition and threshold.
This means our check corresponds to their rule. It does not mean the publisher reviewed or endorses it.