Skip to content

Commit 32f906f

Browse files
committed
store plan flags
1 parent 99cca24 commit 32f906f

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

sqlmesh/core/context.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,11 +1161,11 @@ def plan(
11611161
end: t.Optional[TimeLike] = None,
11621162
execution_time: t.Optional[TimeLike] = None,
11631163
create_from: t.Optional[str] = None,
1164-
skip_tests: bool = False,
1164+
skip_tests: t.Optional[bool] = None,
11651165
restate_models: t.Optional[t.Iterable[str]] = None,
1166-
no_gaps: bool = False,
1167-
skip_backfill: bool = False,
1168-
empty_backfill: bool = False,
1166+
no_gaps: t.Optional[bool] = None,
1167+
skip_backfill: t.Optional[bool] = None,
1168+
empty_backfill: t.Optional[bool] = None,
11691169
forward_only: t.Optional[bool] = None,
11701170
allow_destructive_models: t.Optional[t.Collection[str]] = None,
11711171
no_prompts: t.Optional[bool] = None,
@@ -1178,9 +1178,9 @@ def plan(
11781178
categorizer_config: t.Optional[CategorizerConfig] = None,
11791179
enable_preview: t.Optional[bool] = None,
11801180
no_diff: t.Optional[bool] = None,
1181-
run: bool = False,
1182-
diff_rendered: bool = False,
1183-
skip_linter: bool = False,
1181+
run: t.Optional[bool] = None,
1182+
diff_rendered: t.Optional[bool] = None,
1183+
skip_linter: t.Optional[bool] = None,
11841184
) -> Plan:
11851185
"""Interactively creates a plan.
11861186
@@ -1230,6 +1230,18 @@ def plan(
12301230
Returns:
12311231
The populated Plan object.
12321232
"""
1233+
1234+
flags = {
1235+
k: v for k, v in locals().items() if k not in {"self", "environment"} if v is not None
1236+
}
1237+
skip_tests = skip_tests or False
1238+
no_gaps = no_gaps or False
1239+
skip_backfill = skip_backfill or False
1240+
empty_backfill = empty_backfill or False
1241+
run = run or False
1242+
diff_rendered = diff_rendered or False
1243+
skip_linter = skip_linter or False
1244+
12331245
plan_builder = self.plan_builder(
12341246
environment,
12351247
start=start,
@@ -1253,6 +1265,7 @@ def plan(
12531265
run=run,
12541266
diff_rendered=diff_rendered,
12551267
skip_linter=skip_linter,
1268+
flags=flags,
12561269
)
12571270

12581271
if no_auto_categorization:
@@ -1295,6 +1308,7 @@ def plan_builder(
12951308
run: bool = False,
12961309
diff_rendered: bool = False,
12971310
skip_linter: bool = False,
1311+
flags: t.Optional[t.Dict[str, t.Any]] = None,
12981312
) -> PlanBuilder:
12991313
"""Creates a plan builder.
13001314
@@ -1469,6 +1483,7 @@ def plan_builder(
14691483
engine_schema_differ=self.engine_adapter.SCHEMA_DIFFER,
14701484
interval_end_per_model=max_interval_end_per_model,
14711485
console=self.console,
1486+
flags=flags,
14721487
)
14731488

14741489
def apply(

sqlmesh/core/plan/builder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(
107107
ensure_finalized_snapshots: bool = False,
108108
interval_end_per_model: t.Optional[t.Dict[str, int]] = None,
109109
console: t.Optional[PlanBuilderConsole] = None,
110+
flags: t.Optional[t.Dict[str, t.Any]] = None,
110111
):
111112
self._context_diff = context_diff
112113
self._no_gaps = no_gaps
@@ -134,6 +135,7 @@ def __init__(
134135
self._engine_schema_differ = engine_schema_differ
135136
self._console = console or get_console()
136137
self._choices: t.Dict[SnapshotId, SnapshotChangeCategory] = {}
138+
self._flags = flags
137139

138140
self._start = start
139141
if not self._start and (
@@ -280,6 +282,7 @@ def build(self) -> Plan:
280282
execution_time=self._execution_time,
281283
end_bounded=self._end_bounded,
282284
ensure_finalized_snapshots=self._ensure_finalized_snapshots,
285+
flags=self._flags,
283286
)
284287
self._latest_plan = plan
285288
return plan

sqlmesh/core/plan/definition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Plan(PydanticModel, frozen=True):
6363
effective_from: t.Optional[TimeLike] = None
6464
execution_time: t.Optional[TimeLike] = None
6565

66+
flags: t.Optional[t.Dict[str, t.Any]] = None
67+
6668
@cached_property
6769
def start(self) -> TimeLike:
6870
if self.provided_start is not None:

tests/core/test_plan.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,3 +3105,10 @@ def test_set_choice_for_forward_only_model(make_snapshot):
31053105
plan.snapshots[updated_snapshot.snapshot_id].change_category
31063106
== SnapshotChangeCategory.FORWARD_ONLY
31073107
)
3108+
3109+
3110+
def test_flags(sushi_context: Context):
3111+
plan = sushi_context.plan(no_prompts=True, run=True, execution_time="2025-01-01")
3112+
sushi_context.apply(plan)
3113+
3114+
assert plan.flags == {"no_prompts": True, "run": True, "execution_time": "2025-01-01"}

0 commit comments

Comments
 (0)