Skip to content

fix: skip reservation injection when preOps has an outer DECLARE#65

Open
steps-re wants to merge 1 commit into
masthead-data:mainfrom
steps-re:fix/declare-preops-reservation-skip
Open

fix: skip reservation injection when preOps has an outer DECLARE#65
steps-re wants to merge 1 commit into
masthead-data:mainfrom
steps-re:fix/declare-preops-reservation-skip

Conversation

@steps-re

@steps-re steps-re commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Reservation injection produces invalid BigQuery SQL for any model whose preOps starts with a DECLARE, and this is currently breaking the CI test matrix on every PR.

Details

The package injects SET @@reservation='...'; into an action's pre-operations at publish() time. When a model supplies its own preOps via a chained call — publish(...).preOps('DECLARE ...').query(...) — the reservation statement lands before the user's DECLARE, compiling to ["SET @@reservation=...", "DECLARE ..."]. BigQuery rejects this because a DECLARE must be the first statement in a script, so the model fails to run.

This is exactly the failure making the CI matrix (Dataform 2.4.2 / 3.0.48) red on every PR — e.g. Table test_incremental should NOT have a reservation injected, but found one in preOps. CI only runs on pull_request, so main never exercises the matrix and it went unnoticed.

Fix

Monkeypatch the builder's .preOps() (mirroring the existing .queries() patch) so a later-supplied outer DECLARE removes the reservation statement we injected. Handles both Dataform v3 (proto.preOps) and v2 (contextablePreOps).

Verification

  • Reproduced on main: ./scripts/test-matrix.sh fails at 2.4.2 with the test_incremental DECLARE error; confirmed identical string in the repo's own CI logs.
  • After fix: npx jest89/89 pass; ./scripts/test-matrix.shSUCCESS for both 2.4.2 and 3.0.48. Normal reservation tables/views/operations still get their reservation injected; only DECLARE-carrying models are skipped. eslint exit 0.

This turns the PR CI matrix green (and unblocks the pending dependency PRs). Worth noting CI runs only on pull_request, which is why main hid the regression.

When a table/view/incremental sets its own preOps via a chained
`.preOps('DECLARE ...')` after `publish()`, the reservation
`SET @@reservation=...` statement was injected at build time, before the
DECLARE existed. The result was `[SET, DECLARE]` in the compiled preOps,
which BigQuery rejects because a DECLARE must be the first statement in a
script.

Monkeypatch the builder's `.preOps()` (mirroring the existing `.queries()`
patch for operations) so that when a later-supplied outer DECLARE is
detected, any reservation statement we already injected is removed. The
statement can land in `proto.preOps` (Dataform v3) or `contextablePreOps`
(Dataform v2), so both containers are cleaned.

This fixes the `test_incremental` DECLARE-skip integration check that was
failing the CI matrix for both Dataform 2.4.2 and 3.0.48.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Mike German <mike@stepsventures.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant