Skip to content

Dataform CLI dry run not handling dependent changes #2008

Open

Description

@rsinden

Recently, we added a dataform run --dry-run github action to all of our PRs on our repo containing all of our dataform sqlx files. For simple changes, this works nicely and provides a great CI check before merging to main.

However, recently we have found a few times where this check has failed when adding columns and then using them across 2 dependent views, e.g.

Existing on BigQuery:

  • ViewA
SELECT foo FROM table
  • ViewB
SELECT viewA.foo, table2.bar FROM viewA INNER JOIN table2 USING ...

Then the PR adds baz to both views

  • ViewA
SELECT foo, baz FROM table

(dry run action passes here)

  • ViewB
SELECT viewA.foo, viewA.baz, table2.bar FROM viewA INNER JOIN table2 USING ...

(dry run action fails as viewA.baz does not exist)

Maybe it is our lack of understanding on how we would anticipate this to work, but it seems far from ideal that changes like this do not pass the check we have added.

Activity

  1. dmargol1 commented on Nov 24, 2026

    @dmargol1
    Contributor

    I reproduced this with CLI 3.1.7 against BigQuery. The dry-run code is unchanged on main.

    Cause

    dataform run --dry-run dry-runs each action's SQL separately against the warehouse as it is now. Nothing is created, so a downstream action's references resolve to the deployed version of its upstream, not the version in the PR.

    Example: two deployed views read from a source orders that already has created_at, and the PR adds created_at to both:

    -- order_summary.sqlx
    SELECT order_id, customer_id, amount, created_at FROM ${ref("orders")}
    
    -- customer_totals.sqlx
    SELECT customer_id, SUM(amount) AS total, MAX(created_at) AS last_order
    FROM ${ref("order_summary")} GROUP BY customer_id
    Table dry run success:  issue2008.order_summary [view]
    Dataset dry run failed:  issue2008.customer_totals [view]
      bigquery error: Unrecognized name: created_at at [2:47]
    

    ("Dataset" in the failure line is a labelling bug; it's a view.)

    A real run of the same change succeeds, because order_summary is replaced before customer_totals runs. The same thing happens when the PR adds a new upstream action: the downstream dry run fails with Not found: Table ....

    It can also go wrong the other way. If a PR removes a column from an upstream view, an unchanged downstream view that still selects it passes the dry run, then fails in the real run.

    So dry runs can both reject valid coordinated schema changes and miss failures caused by upstream columns being removed or changing type.

    Workaround

    Do a real run into per-PR datasets instead of a dry run:

    dataform run --schema-suffix pr_123 --actions customer_totals --include-deps

    Caveats:

    • The suffix applies only to actions Dataform manages. Declarations (sources) still resolve to their real datasets.
    • --include-deps is needed so managed upstreams, such as a table the action joins, also exist in the suffixed dataset. Without it the run fails with Not found.
    • Only references through Dataform's helpers (ref(), self(), etc.) are redirected. Hard-coded table names, including in operations and pre/post-operations, still point at the original datasets.
    • Creating views doesn't scan data, but building upstream tables and running assertions or operations is billed, even if the PR changes only views.
    • Expire or drop the PR datasets afterwards.

    Possible fix

    An opt-in dry-run mode could check each downstream action against the upstream changes in the same run. It would replace references to upstream actions with empty, typed stand-ins (SELECT CAST(NULL AS ...) ... LIMIT 0) built from the upstream dry-run schemas that #2433 adds. It would start narrow: only upstreams with simple outputs (e.g. views and plain tables) whose schemas can be reproduced exactly. Everything else, such as incremental writes, scripts, operations, and types that the reported schema represents lossily, would be checked as it is today, and the output would say so. I tried this by hand with bq query --dry_run: it accepts the coordinated change above and rejects the dropped-column case.

    Would the maintainers accept this as a follow-up after #2433? If so, I'm happy to work on it.

  2. apilaskowski commented on Nov 25, 2026

    @apilaskowski
    Collaborator

    @dmargol1 It would be great :)

  3. dmargol1 commented on Nov 26, 2026

    @dmargol1
    Contributor

    @apilaskowski
    Thanks! I've tested the stand-in approach against BigQuery. Before opening the feature PRs, I'd like feedback on the reference classifier and coverage reporting below. I also found an independent bug in the existing SQL comment/literal stripper, which I've submitted separately as #2501.

    Mechanism

    When an upstream action's dry run passes and reports a schema, its downstreams are dry-run with an empty, typed stand-in for it: a CTE named with the exact backticked path that ref() compiles to, added to the query's leading WITH clause, or a new one.

    WITH `proj.ds.order_summary` AS (SELECT CAST(NULL AS INT64) AS `order_id`, CAST(NULL AS INT64) AS `customer_id`, CAST(NULL AS NUMERIC) AS `amount`, CAST(NULL AS TIMESTAMP) AS `created_at` LIMIT 0) SELECT customer_id, SUM(amount) AS total, MAX(created_at) AS last_order
    FROM `proj.ds.order_summary` GROUP BY customer_id

    With this, the coordinated change from my earlier comment passes, and a downstream that selects a dropped column fails. For built-in assertions on a table added in the same PR, the generated assertion view definitions dry-run successfully instead of failing with Not found: Table.

    When stand-ins aren't used

    A CTE isn't interchangeable with a table: APPENDS(TABLE ...) and CHANGES(TABLE ...) fail on one (CDC streams are only supported over a base table), and so do FOR SYSTEM_TIME AS OF and TABLESAMPLE. So I'd use stand-ins only where every reference to a stubbed path is a plain table reference in FROM / JOIN. Any reference form the classifier doesn't recognize falls back to today's check. The cost is a small classifier to maintain.

    It also falls back when:

    • the upstream isn't a view or non-incremental table in the run, sets require_partition_filter, or its dry run reports no schema (e.g. when a preceding DROP stops validation before the defining query);
    • the schema can't be reproduced exactly, e.g. collation on a nested field;
    • the downstream is a materialized view, which must reference a base table, or a stubbed path appears in its pre- or post-operations, which the CTE doesn't reach.

    Reporting ships with the feature

    An action can be checked partly against proposed schemas and partly against deployed ones. For example, a hard-coded path spelled differently from ref() output still reads the deployed table. So each action's result would record, in the protos, which upstreams were stubbed and which fell back and why. It would also record whether proposed-schema coverage is complete for its in-run dependencies, including theirs transitively; references whose coverage can't be established count as partial. Bytes and referenced tables would be marked synthetic: a join with an empty stand-in reported 0 bytes even for a real public table. The console would show partial and fallback results as such, not as a plain dry run success.

    The upstream schemas come from the job statistics #2433 adds, but in raw form, since its schemaFields drops collation.

    Questions

    1. Are you OK with maintaining the reference classifier?
    2. Does the reporting contract above (per-action coverage fields in the protos, partial results shown as such) work for you?

    If those are fine, I'd open a PR with the pure helpers (ready now), then one with the flag, wiring, classifier and reporting together, mostly in a helper module to keep run.ts contained. Unless you'd prefer otherwise, I'd go with these defaults:

    • CLI only, opt-in through a flag such as run --dry-run --dry-run-stand-ins;
    • stand-ins for every eligible upstream in the run, since the CLI can't tell which ones changed;
    • no second dry run for bytes;
    • for an upstream in a dataset that doesn't exist yet, the schema from the validation query the CLI already runs, marked as not covering the wrapper script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions