Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
dbt Labs · dbt Analytics Engineering

State Selection, Defer, and dbt retry

dbt Analytics Engineering · Lesson 17 of 17 · 2:06:30

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the dbt Analytics Engineering Certification exam. In this lesson: state and the manifest.json and run_results.json artifacts, state:modified and its subselectors, defer and --favor-state, and dbt retry. Includes three original practice questions, with Orchardline Meal Kits, a fictional meal-kit company, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Two hours for one change

Orchardline's project now has four hundred models, and the CI build takes two hours, even when a pull request changes a single model. And when one model failed at three in the morning, the team reran the whole project. This lesson covers state and artifacts, state selection, defer, and dbt retry.

State and artifacts

dbt operations are stateless and idempotent: given the same code and the same raw data, a run gives the same result, whatever ran before. But every run writes artifacts to the target folder, like the manifest, which describes every node of the project, and run results, which holds the status of each node. Passing the folder of a previous run's artifacts with the state flag lets dbt compare the current project with that run. Three features rely on it: state selection, deferral, and dbt clone. Usually, the state comes from production: a job saves its artifacts, and development or CI runs compare against them.

State selection

The state method compares each node with the manifest: state new selects nodes that did not exist, and state modified selects new nodes, plus any change to existing ones. Subselectors narrow it down, like state modified dot body for SQL changes, or configs, relation, macros, and contract. Add a plus sign after it, and dbt also builds everything downstream: that is the core of slim CI, which builds only what a change can affect. Some changes do not count: tags and meta are metadata only, and a model whose variable or environment variable changes value is usually not detected. A model that calls a changed macro, on the other hand, is marked as modified.

Defer

With defer, you run a few models without building their parents first: a ref to a parent that is not selected, and does not exist in your schema, resolves to the production object from the state manifest. It needs both the defer flag and the state flag, or their environment variables. The favor state flag goes further, and uses the production object even when your schema has one, as long as the node is not selected. Ephemeral models are never deferred, and beware of mixing environments: a relationships test may compare development rows with production rows.

dbt retry

dbt retry reruns the last command from the point of failure: the nodes that failed, and the ones that were skipped because of them. It reads the run results file of the previous invocation, so nothing has to be selected again. It works with build, run, test, seed, snapshot, compile, clone, and a few other commands, and if the last command succeeded, it does nothing. If the failure happened before any node ran, like a connection error, there is nothing to retry: fix the cause, then run the command again. A retry without a fix gives the same result, and for finer control, the result method selects nodes by their previous status, like result error.

Recap

Let's recap. dbt is stateless, but every run writes artifacts, like the manifest and run results, to the target folder. The state flag points to a previous manifest, usually from production. State modified selects changed nodes, and a plus sign adds everything downstream, for slim CI. Defer resolves refs to unbuilt parents from production, and needs the defer and state flags. And dbt retry reruns the last command from the point of failure, using run results.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. To find the models that changed since the production run, which artifact does --state need?

    • run_results.json
    • sources.json
    • catalog.json
    • manifest.json
    Show the answer

    manifest.json

    The manifest describes every node of the project, so dbt can compare it with the current code. “run_results.json” is wrong, since run results holds the status of each node, not its definition. “sources.json” is wrong, since sources dot json holds freshness results. And “catalog.json” is wrong, since the catalog holds warehouse metadata for the documentation site.

  2. A developer changed only fct_revenue, and wants to build it in development without building its forty upstream models. The production manifest is in prod/. Which command fits?

    • dbt build -s +fct_revenue --defer --state prod
    • dbt clone -s fct_revenue --state prod
    • dbt build -s fct_revenue --defer --state prod
    • dbt build -s fct_revenue --full-refresh
    Show the answer

    dbt build -s fct_revenue --defer --state prod

    With defer and the production state, refs to the unbuilt parents resolve to production, so only the revenue mart is built. “dbt build -s +fct_revenue --defer --state prod” is wrong, since the plus sign selects every parent, and builds them all. “dbt clone -s fct_revenue --state prod” is wrong, since clone copies the production mart, instead of building the changed one. And “dbt build -s fct_revenue --full-refresh” is wrong, since a full refresh does not help, when the parents are missing from the schema.

  3. A nightly dbt build failed at model 80 of 400, because of a missing permission on one schema, now fixed. How should the team resume?

    • dbt retry
    • dbt build --full-refresh
    • dbt build --select state:modified+
    • dbt build
    Show the answer

    dbt retry

    Dbt retry reads the run results, and reruns only the nodes that failed or were skipped. “dbt build --full-refresh” is wrong, since a full refresh rebuilds every model from scratch. “dbt build --select state:modified+” is wrong, since state modified selects code changes, and nothing changed in the code. And “dbt build” would only rebuild the whole project, including the nodes that already succeeded.