Skip to content

Commit f33eb8d

Browse files
authored
fix: give the refused FULL backfill of a cursor-intrinsic model its own code S204 (#1525)
* fix: give the refused FULL backfill of a cursor-intrinsic model its own code A FULL backfill of a non-microbatch model whose SQL reads __cursor_start() or __cursor_end() is refused, because a full rebuild has no cursor interval. The refusal used the planner's default code S000, so the plan JSON, the control API and the UI could not tell it apart from any other planner input error. It now fails with S204, listed with the other planner codes, keeping its message and the remedy that names --start-cursor-ts and --end-cursor-ts. * fix: name every FULL backfill cause in the S204 docs and check the code in the unit test * chore: set the Python bindings cap to its measured size
1 parent 25ac381 commit f33eb8d

6 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎crates/sqlbuild-python-planner/src/planner_phases/constants.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub(crate) const DOWNGRADE_HISTORY_DAYS: i64 = 90;
2828

2929
pub(crate) const FULL_REFRESH_DISABLED_REBUILD_CODE: &str = "S203";
3030

31+
/// A FULL backfill of a non-microbatch model whose SQL reads the cursor intrinsics.
32+
pub(crate) const FULL_BACKFILL_WITHOUT_INTERVAL_CODE: &str = "S204";
33+
3134
pub(crate) const MISSING_UPSTREAM_CODE: &str = "S301";
3235

3336
pub(crate) const RETENTION_DECREASE: &str = "decrease";

‎crates/sqlbuild-python-planner/src/planner_resolution/_helpers/references/orchestration.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Model, function and SQL-hook orchestration through adapter-owned rendering.
22
3+
use crate::planner_phases::constants::FULL_BACKFILL_WITHOUT_INTERVAL_CODE;
34
use crate::planner_resolution::_helpers::cursor::cursor_model::{
45
compute_model_cursor_bounds, unbounded,
56
};
@@ -169,6 +170,7 @@ fn unresolved_bounds_error(py: Python<'_>, name: &str, cause: Option<&str>) -> P
169170
let error = error_class(py, ErrorId::PlannerInput)?;
170171
let kwargs = PyDict::new(py);
171172
let message = if let Some(cause) = cause {
173+
kwargs.set_item("code", FULL_BACKFILL_WITHOUT_INTERVAL_CODE)?;
172174
kwargs.set_item("help", "rebuild it with an explicit cursor interval (--start-cursor-ts and --end-cursor-ts, or the -int forms), or make it a microbatch model so a full rebuild can run batch by batch")?;
173175
format!(
174176
"Model '{name}' was given a FULL backfill ({cause}), but it uses cursor intrinsics and a non-microbatch full rebuild has no cursor interval"

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/incremental.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ WHERE ordered_at >= __cursor_start()
263263
AND ordered_at < __cursor_end()
264264
```
265265

266-
`__cursor_start()` is the effective inclusive start and `__cursor_end()` is the effective exclusive end after cursor floors, lookback, replay policy, and command-line overrides have been applied. The intrinsics accept no arguments and are only valid in built-in cursor incremental model query SQL. They are rejected in functions, hooks, audits, SQL tests and scenarios, source expressions, non-incremental or cursorless models, custom materializations, and non-microbatch full refreshes. A non-microbatch model given a FULL backfill by `--full-refresh` fails with a message naming that cause; pass an explicit interval with `--start-cursor-ts` and `--end-cursor-ts` (or the `-int` forms) to rebuild it.
266+
`__cursor_start()` is the effective inclusive start and `__cursor_end()` is the effective exclusive end after cursor floors, lookback, replay policy, and command-line overrides have been applied. The intrinsics accept no arguments and are only valid in built-in cursor incremental model query SQL. They are rejected in functions, hooks, audits, SQL tests and scenarios, source expressions, non-incremental or cursorless models, custom materializations, and non-microbatch full refreshes. A non-microbatch model planned as a FULL backfill, for example by `--full-refresh`, fails planning with `S204`, naming the cause; pass an explicit interval with `--start-cursor-ts` and `--end-cursor-ts` (or the `-int` forms) to rebuild it.
267267

268268
In microbatch mode, the intrinsics resolve to each batch's concrete bounds. A microbatch full refresh discovers its range from current inputs while ignoring the old destination watermark.
269269

‎tests/e2e/src/sqlbuild/cli/commands/main/build/own_change_replay/test_own_change_replay.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import json
6+
import subprocess
57
from datetime import date
68
from pathlib import Path
79
from typing import Any
@@ -29,6 +31,7 @@
2931
insert_table_between_upstream_and_view,
3032
mark_first_day,
3133
merge_downstream_files,
34+
plan,
3235
plan_models,
3336
relation_types,
3437
rename_upstream_with_cli,
@@ -341,6 +344,7 @@ def test_given_full_refresh_false_caller_when_function_forces_full_rebuild_then_
341344
RefusedPlanTestCase(
342345
description="explicit full refresh of a cursor-intrinsic merge names the FULL cause",
343346
expected_fragments=(
347+
"error[S204]",
344348
"Model 'downstream' was given a FULL backfill (--full-refresh)",
345349
"non-microbatch full rebuild has no cursor interval",
346350
"--start-cursor-ts",
@@ -361,6 +365,11 @@ def test_given_full_refresh_flag_on_cursor_intrinsic_merge_when_planning_then_na
361365
args=("--full-refresh", "--select", "downstream"),
362366
expected=test_case.expected_fragments,
363367
)
368+
refused: subprocess.CompletedProcess[str] = plan(
369+
project_dir=project_dir, args=("--json", "--full-refresh", "--select", "downstream")
370+
)
371+
assert refused.returncode != 0, refused.stdout + refused.stderr
372+
assert json.loads(refused.stdout)["error"]["code"] == "S204", refused.stdout + refused.stderr
364373

365374

366375
@pytest.mark.parametrize(

‎tests/unit/src/sqlbuild/compiler/planner/_helpers/resolve/test_cursor_intrinsics.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_given_missing_cursor_interval_when_resolving_then_rejects_intrinsics(
106106
) -> None:
107107
model: CompiledModelView = build_cursor_intrinsic_model(config_values=test_case.model_config)
108108

109-
with pytest.raises(PlannerInputError, match=test_case.expected_error_fragment):
109+
with pytest.raises(PlannerInputError, match=test_case.expected_error_fragment) as raised:
110110
resolve_model_sql(
111111
adapter=DuckDbAdapter(),
112112
model=model,
@@ -116,3 +116,4 @@ def test_given_missing_cursor_interval_when_resolving_then_rejects_intrinsics(
116116
full_refresh=test_case.full_refresh,
117117
cursor_overrides=CursorOverridePair(),
118118
)
119+
assert raised.value.code == "S204"

‎website/src/content/docs/docs/concepts/incremental.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ WHERE ordered_at >= __cursor_start()
252252
AND ordered_at < __cursor_end()
253253
```
254254

255-
`__cursor_start()` is the effective inclusive start and `__cursor_end()` is the effective exclusive end after cursor floors, lookback, replay policy, and command-line overrides have been applied. The intrinsics accept no arguments and are only valid in built-in cursor incremental model query SQL. They are rejected in functions, hooks, audits, SQL tests and scenarios, source expressions, non-incremental or cursorless models, custom materializations, and non-microbatch full refreshes. A non-microbatch model given a FULL backfill by `--full-refresh` fails with a message naming that cause; pass an explicit interval with `--start-cursor-ts` and `--end-cursor-ts` (or the `-int` forms) to rebuild it.
255+
`__cursor_start()` is the effective inclusive start and `__cursor_end()` is the effective exclusive end after cursor floors, lookback, replay policy, and command-line overrides have been applied. The intrinsics accept no arguments and are only valid in built-in cursor incremental model query SQL. They are rejected in functions, hooks, audits, SQL tests and scenarios, source expressions, non-incremental or cursorless models, custom materializations, and non-microbatch full refreshes. A non-microbatch model planned as a FULL backfill, for example by `--full-refresh`, fails planning with `S204`, naming the cause; pass an explicit interval with `--start-cursor-ts` and `--end-cursor-ts` (or the `-int` forms) to rebuild it.
256256

257257
In microbatch mode, the intrinsics resolve to each batch's concrete bounds. A microbatch full refresh discovers its range from current inputs while ignoring the old destination watermark.
258258

0 commit comments

Comments
 (0)