Skip to content

Commit ddca09d

Browse files
committed
fix(dbt): give dbt-appropriate remediation when a missing origin needs confirmation
1 parent 27481cf commit ddca09d

7 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/project-configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ missing_migration_origin = "deny"
235235

236236
`sqlbuild_local.toml` can override the value for a target.
237237

238-
The policy covers only origins with no build history in the target. A model origin that SQLBuild built in this target but can no longer see, because of permissions or because it was dropped outside SQLBuild, always stops the build with `M102`. Column origins have no such history, so `M109` always follows the policy. `sqb dbt run` and `sqb dbt build` apply the policy too, without a confirmation flag: they ask on a terminal and stop otherwise.
238+
The policy covers only origins with no build history in the target. A model origin that SQLBuild built in this target but can no longer see, because of permissions or because it was dropped outside SQLBuild, always stops the build with `M102`. Column origins have no such history, so `M109` always follows the policy. `sqb dbt run` and `sqb dbt build` apply the policy too, but have no confirmation flag: they ask on a terminal and stop otherwise. In non-interactive dbt runs, build the affected models with `sqb build --allow-missing-migration-origin` and leave them out of the dbt selection, or set the target's `missing_migration_origin` to `allow`.
239239

240240
### Clone policies
241241

‎src/sqlbuild/cli/commands/_helpers/build_planning/confirmation.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def confirm_typed_action(
1111
*,
1212
action: str,
13-
flag: str,
13+
non_interactive_help: str,
1414
warning: str,
1515
expected: str,
1616
input_stream: TextIO,
@@ -23,7 +23,7 @@ def confirm_typed_action(
2323
raise CliUserError(
2424
f"{action} requires confirmation",
2525
code=code,
26-
help=f"Pass {flag} to confirm in non-interactive runs.",
26+
help=non_interactive_help,
2727
)
2828
_ = output_stream.write(f"{warning}\n\n")
2929
_ = output_stream.write(f"Type `{expected}` to continue: ")

‎src/sqlbuild/cli/commands/_helpers/build_planning/plan_policies.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sqlbuild.cli.commands._helpers.build_planning.table_type import (
2020
enforce_table_type_downgrade_policy,
2121
)
22+
from sqlbuild.cli.commands.constants import MISSING_ORIGIN_BUILD_HELP
2223
from sqlbuild.cli.commands.exceptions import CliUserError
2324
from sqlbuild.cli.commands.models import BuildCommandRequest, BuildInvocation
2425
from sqlbuild.compiler.migrations.types import ColumnMigrationDecision, MigrationDecision
@@ -49,6 +50,7 @@ def enforce_build_plan_policies(
4950
enforce_migration_plan_policies(
5051
plan=plan,
5152
allow_missing_migration_origin=request.allow_missing_migration_origin,
53+
non_interactive_help=MISSING_ORIGIN_BUILD_HELP,
5254
input_stream=sys.stdin,
5355
output_stream=sys.stdout,
5456
)
@@ -83,6 +85,7 @@ def enforce_migration_plan_policies(
8385
*,
8486
plan: PlanOutput,
8587
allow_missing_migration_origin: bool,
88+
non_interactive_help: str,
8689
input_stream: TextIO,
8790
output_stream: TextIO,
8891
) -> None:
@@ -93,6 +96,7 @@ def enforce_migration_plan_policies(
9396
_confirm_missing_origins(
9497
plan=plan,
9598
allow_missing_migration_origin=allow_missing_migration_origin,
99+
non_interactive_help=non_interactive_help,
96100
input_stream=input_stream,
97101
output_stream=output_stream,
98102
)
@@ -182,6 +186,7 @@ def _confirm_missing_origins(
182186
*,
183187
plan: PlanOutput,
184188
allow_missing_migration_origin: bool,
189+
non_interactive_help: str,
185190
input_stream: TextIO,
186191
output_stream: TextIO,
187192
) -> None:
@@ -203,7 +208,7 @@ def _confirm_missing_origins(
203208
listed: str = ", ".join(f"'{name}'" for name in names)
204209
confirm_typed_action(
205210
action=f"building {listed} without its missing migrate_from origin",
206-
flag="--allow-missing-migration-origin",
211+
non_interactive_help=non_interactive_help,
207212
warning=f"The migrate_from origin of {listed} does not exist in this target; nothing "
208213
"will be migrated.",
209214
expected=(

‎src/sqlbuild/cli/commands/_helpers/dbt/sqlbuild_work.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
BuildProgressCallbacks,
1818
format_build_footer,
1919
)
20+
from sqlbuild.cli.commands.constants import MISSING_ORIGIN_DBT_HELP
2021
from sqlbuild.cli.commands.models import DbtSqlbuildWorkContext
2122
from sqlbuild.cli.progress.classes.connection_progress_reporter import ConnectionProgressReporter
2223
from sqlbuild.cli.progress.main._execution_header import format_execution_header
@@ -56,6 +57,7 @@ def execute_sqlbuild_build_work(
5657
enforce_migration_plan_policies(
5758
plan=plan_output,
5859
allow_missing_migration_origin=False,
60+
non_interactive_help=MISSING_ORIGIN_DBT_HELP,
5961
input_stream=sys.stdin,
6062
output_stream=output_stream,
6163
)

‎src/sqlbuild/cli/commands/constants.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@
103103
QUERY_DIFF_INCOMPLETE_PREPARATION_CODES: frozenset[str] = frozenset(
104104
{"C229", "C230", "C231", "C232", "C233", "C234", "C235", "C240", "C244"}
105105
)
106+
MISSING_ORIGIN_BUILD_HELP: str = (
107+
"Pass --allow-missing-migration-origin to confirm in non-interactive runs."
108+
)
109+
MISSING_ORIGIN_DBT_HELP: str = (
110+
"sqb dbt has no confirmation flag: confirm on an interactive terminal, build the affected "
111+
"models with sqb build --allow-missing-migration-origin and leave them out of this dbt "
112+
"selection, or set the target's missing_migration_origin to 'allow'."
113+
)
106114
QUERY_DIFF_INCOMPLETE_EXECUTION_CODES: frozenset[str] = frozenset({"C237", "C238", "C239"})

‎tests/e2e/src/sqlbuild/cli/commands/main/dbt/test_execute.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,12 @@ def test_given_failing_dbt_model_when_running_command_then_dependent_sqlbuild_is
551551
DbtMissingOriginE2ETestCase(
552552
description="dbt build refuses a missing origin that needs confirmation",
553553
command=("dbt", "build", "--select", "tag:sqb_only"),
554-
expected_output="--allow-missing-migration-origin",
554+
expected_output="build the affected models with sqb build --allow-missing-migration-origin",
555555
),
556556
DbtMissingOriginE2ETestCase(
557557
description="dbt run refuses a missing origin that needs confirmation",
558558
command=("dbt", "run", "--select", "local_only"),
559-
expected_output="--allow-missing-migration-origin",
559+
expected_output="build the affected models with sqb build --allow-missing-migration-origin",
560560
),
561561
],
562562
ids=lambda case: case.description,
@@ -575,4 +575,5 @@ def test_given_missing_origin_requiring_confirmation_when_running_dbt_then_refus
575575

576576
assert result.returncode == 1, result.stdout + result.stderr
577577
assert test_case.expected_output in result.stdout + result.stderr
578+
assert "Pass --allow-missing-migration-origin" not in result.stdout + result.stderr
578579
assert not table_exists(db_path=project_dir / "dbt_interop.duckdb", table_name="local_only")

‎website/src/content/docs/docs/concepts/project-configuration.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ missing_migration_origin = "deny"
212212

213213
`sqlbuild_local.toml` can override the value for a target.
214214

215-
The policy covers only origins with no build history in the target. A model origin that SQLBuild built in this target but can no longer see, because of permissions or because it was dropped outside SQLBuild, always stops the build with `M102`. Column origins have no such history, so `M109` always follows the policy. `sqb dbt run` and `sqb dbt build` apply the policy too, without a confirmation flag: they ask on a terminal and stop otherwise.
215+
The policy covers only origins with no build history in the target. A model origin that SQLBuild built in this target but can no longer see, because of permissions or because it was dropped outside SQLBuild, always stops the build with `M102`. Column origins have no such history, so `M109` always follows the policy. `sqb dbt run` and `sqb dbt build` apply the policy too, but have no confirmation flag: they ask on a terminal and stop otherwise. In non-interactive dbt runs, build the affected models with `sqb build --allow-missing-migration-origin` and leave them out of the dbt selection, or set the target's `missing_migration_origin` to `allow`.
216216

217217
### Clone policies
218218

0 commit comments

Comments
 (0)