Skip to content

Commit a392953

Browse files
authored
Fix: prompt if there are any uncategorized snapshots in a plan (#4498)
1 parent ac25787 commit a392953

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

sqlmesh/core/context.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,11 @@ def plan(
12691269
skip_linter=skip_linter,
12701270
)
12711271

1272-
if no_auto_categorization:
1272+
plan = plan_builder.build()
1273+
1274+
if no_auto_categorization or plan.uncategorized:
12731275
# Prompts are required if the auto categorization is disabled
1276+
# or if there are any uncategorized snapshots in the plan
12741277
no_prompts = False
12751278

12761279
self.console.plan(
@@ -1281,7 +1284,7 @@ def plan(
12811284
no_prompts=no_prompts if no_prompts is not None else self.config.plan.no_prompts,
12821285
)
12831286

1284-
return plan_builder.build()
1287+
return plan
12851288

12861289
@python_api_analytics
12871290
def plan_builder(

tests/core/test_context.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414
from sqlglot import ParseError, exp, parse_one, Dialect
1515
from sqlglot.errors import SchemaError
1616

17-
from sqlmesh.core.config.gateway import GatewayConfig
1817
import sqlmesh.core.constants
18+
from sqlmesh.cli.example_project import init_example_project
1919
from sqlmesh.core import dialect as d, constants as c
2020
from sqlmesh.core.config import (
21+
load_configs,
22+
AutoCategorizationMode,
23+
CategorizerConfig,
2124
Config,
2225
DuckDBConnectionConfig,
2326
EnvironmentSuffixTarget,
27+
GatewayConfig,
28+
LinterConfig,
2429
ModelDefaultsConfig,
30+
PlanConfig,
2531
SnowflakeConnectionConfig,
26-
LinterConfig,
27-
load_configs,
2832
)
2933
from sqlmesh.core.context import Context
3034
from sqlmesh.core.console import create_console, get_console
@@ -2071,3 +2075,40 @@ def test_audit():
20712075
context.plan(no_prompts=True, auto_apply=True)
20722076

20732077
assert context.audit(models=["dummy"], start="2020-01-01", end="2020-01-01") is True
2078+
2079+
2080+
def test_prompt_if_uncategorized_snapshot(mocker: MockerFixture, tmp_path: Path) -> None:
2081+
init_example_project(tmp_path, dialect="duckdb")
2082+
2083+
config = Config(
2084+
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
2085+
plan=PlanConfig(
2086+
auto_categorize_changes=CategorizerConfig(
2087+
external=AutoCategorizationMode.OFF,
2088+
python=AutoCategorizationMode.OFF,
2089+
sql=AutoCategorizationMode.OFF,
2090+
seed=AutoCategorizationMode.OFF,
2091+
),
2092+
),
2093+
)
2094+
context = Context(paths=tmp_path, config=config)
2095+
context.plan(no_prompts=True, auto_apply=True)
2096+
2097+
incremental_model = context.get_model("sqlmesh_example.incremental_model")
2098+
incremental_model_query = incremental_model.render_query()
2099+
new_incremental_model_query = t.cast(exp.Select, incremental_model_query).select("1 AS z")
2100+
context.upsert_model("sqlmesh_example.incremental_model", query=new_incremental_model_query)
2101+
2102+
mock_console = mocker.Mock()
2103+
spy_plan = mocker.spy(mock_console, "plan")
2104+
context.console = mock_console
2105+
2106+
context.plan()
2107+
2108+
calls = spy_plan.mock_calls
2109+
assert len(calls) == 1
2110+
2111+
# Show that the presence of uncategorized snapshots forces no_prompts to
2112+
# False instead of respecting the default plan config value, which is True
2113+
assert calls[0].kwargs["no_prompts"] == False
2114+
assert context.config.plan.no_prompts == True

0 commit comments

Comments
 (0)