Skip to content

Commit d3717b3

Browse files
committed
fix tests
1 parent 8ace714 commit d3717b3

16 files changed

Lines changed: 98 additions & 79 deletions

File tree

examples/multi/repo_1/models/a.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name bronze.a
2+
name bronze.a,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_1/models/b.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name bronze.b
2+
name bronze.b,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_2/models/c.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.c
2+
name silver.c,
3+
kind FULL
34
);
45

56
SELECT DISTINCT col_a

examples/multi/repo_2/models/d.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.d
2+
name silver.d,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_2/models/e.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.e
2+
name silver.e,
3+
kind FULL
34
);
45

56
SELECT

examples/sushi/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,7 @@
192192
},
193193
before_all=before_all,
194194
)
195+
196+
hash_md5_naming_config = config.copy(update={"physical_table_naming_convention": "hash_md5"})
197+
198+
table_only_naming_config = config.copy(update={"physical_table_naming_convention": "table_only"})

sqlmesh/core/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4074,8 +4074,8 @@ def _format_node_error(ex: NodeExecutionFailedError) -> str:
40744074
node_name = ""
40754075
if isinstance(error.node, SnapshotId):
40764076
node_name = error.node.name
4077-
elif isinstance(error.node, tuple):
4078-
node_name = error.node[0]
4077+
elif hasattr(error.node, "snapshot_name"):
4078+
node_name = error.node.snapshot_name
40794079

40804080
msg = _format_node_error(error)
40814081
msg = " " + msg.replace("\n", "\n ")

sqlmesh/core/context_diff.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ def create(
222222
infer_python_dependencies=infer_python_dependencies,
223223
)
224224

225-
previous_environment_statements = state_reader.get_environment_statements(environment)
225+
previous_environment_statements = (
226+
state_reader.get_environment_statements(env.name) if env else []
227+
)
226228

227229
if existing_env and always_recreate_environment:
228230
previous_plan_id: t.Optional[str] = existing_env.plan_id
@@ -288,7 +290,7 @@ def create_no_diff(cls, environment: str, state_reader: StateReader) -> ContextD
288290
previous_finalized_snapshots=env.previous_finalized_snapshots,
289291
previous_requirements=env.requirements,
290292
requirements=env.requirements,
291-
previous_environment_statements=[],
293+
previous_environment_statements=environment_statements,
292294
environment_statements=environment_statements,
293295
previous_gateway_managed_virtual_layer=env.gateway_managed,
294296
gateway_managed_virtual_layer=env.gateway_managed,

sqlmesh/core/plan/builder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from sqlmesh.core.context_diff import ContextDiff
1818
from sqlmesh.core.environment import EnvironmentNamingInfo
19-
from sqlmesh.core.plan.common import should_force_rebuild
19+
from sqlmesh.core.plan.common import should_force_rebuild, is_breaking_kind_change
2020
from sqlmesh.core.plan.definition import (
2121
Plan,
2222
SnapshotMapping,
@@ -597,7 +597,7 @@ def _categorize_snapshots(
597597
forward_only = self._forward_only or self._is_forward_only_change(s_id)
598598
if forward_only and s_id.name in self._context_diff.modified_snapshots:
599599
new, old = self._context_diff.modified_snapshots[s_id.name]
600-
if should_force_rebuild(old, new) or snapshot.is_seed:
600+
if is_breaking_kind_change(old, new) or snapshot.is_seed:
601601
# Breaking kind changes and seed changes can't be forward-only.
602602
forward_only = False
603603

@@ -622,7 +622,7 @@ def _categorize_snapshot(
622622
if self._context_diff.directly_modified(s_id.name):
623623
if self._auto_categorization_enabled:
624624
new, old = self._context_diff.modified_snapshots[s_id.name]
625-
if should_force_rebuild(old, new):
625+
if is_breaking_kind_change(old, new):
626626
snapshot.categorize_as(SnapshotChangeCategory.BREAKING, False)
627627
return
628628

@@ -780,7 +780,7 @@ def _is_forward_only_change(self, s_id: SnapshotId) -> bool:
780780
if snapshot.name in self._context_diff.modified_snapshots:
781781
_, old = self._context_diff.modified_snapshots[snapshot.name]
782782
# If the model kind has changed in a breaking way, then we can't consider this to be a forward-only change.
783-
if snapshot.is_model and should_force_rebuild(old, snapshot):
783+
if snapshot.is_model and is_breaking_kind_change(old, snapshot):
784784
return False
785785
return (
786786
snapshot.is_model and snapshot.model.forward_only and bool(snapshot.previous_versions)

sqlmesh/core/plan/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55

66
def should_force_rebuild(old: Snapshot, new: Snapshot) -> bool:
7-
if new.is_view:
7+
if new.is_view and new.is_indirect_non_breaking and not new.is_forward_only:
88
# View models always need to be rebuilt to reflect updated upstream dependencies.
99
return True
10+
return is_breaking_kind_change(old, new)
11+
12+
13+
def is_breaking_kind_change(old: Snapshot, new: Snapshot) -> bool:
1014
if old.virtual_environment_mode != new.virtual_environment_mode:
1115
# If the virtual environment mode has changed, then we need to rebuild
1216
return True

0 commit comments

Comments
 (0)