Skip to content

Commit fe38af7

Browse files
committed
Fix: Seed model changes when using the dev-only VDE mode
1 parent da57f8e commit fe38af7

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,21 +2102,18 @@ def create(
21022102
return
21032103

21042104
super().create(table_name, model, is_table_deployable, render_kwargs, **kwargs)
2105-
if is_table_deployable:
2106-
# For seeds we insert data at the time of table creation.
2107-
try:
2108-
for index, df in enumerate(model.render_seed()):
2109-
if index == 0:
2110-
self._replace_query_for_model(
2111-
model, table_name, df, render_kwargs, **kwargs
2112-
)
2113-
else:
2114-
self.adapter.insert_append(
2115-
table_name, df, target_columns_to_types=model.columns_to_types
2116-
)
2117-
except Exception:
2118-
self.adapter.drop_table(table_name)
2119-
raise
2105+
# For seeds we insert data at the time of table creation.
2106+
try:
2107+
for index, df in enumerate(model.render_seed()):
2108+
if index == 0:
2109+
self._replace_query_for_model(model, table_name, df, render_kwargs, **kwargs)
2110+
else:
2111+
self.adapter.insert_append(
2112+
table_name, df, target_columns_to_types=model.columns_to_types
2113+
)
2114+
except Exception:
2115+
self.adapter.drop_table(table_name)
2116+
raise
21202117

21212118
def insert(
21222119
self,

tests/core/test_integration.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,20 +2933,24 @@ def test_virtual_environment_mode_dev_only_seed_model_change(
29332933

29342934
context.load()
29352935
seed_model_snapshot = context.get_snapshot("sushi.waiter_names")
2936+
plan = context.plan_builder("dev").build()
2937+
assert plan.directly_modified == {seed_model_snapshot.snapshot_id}
2938+
assert len(plan.missing_intervals) == 2
2939+
context.apply(plan)
2940+
2941+
actual_seed_df_in_dev = context.fetchdf("SELECT * FROM sushi__dev.waiter_names WHERE id = 123")
2942+
assert actual_seed_df_in_dev.to_dict("records") == [{"id": 123, "name": "New Test Name"}]
2943+
actual_seed_df_in_prod = context.fetchdf("SELECT * FROM sushi.waiter_names WHERE id = 123")
2944+
assert actual_seed_df_in_prod.empty
2945+
29362946
plan = context.plan_builder("prod").build()
29372947
assert plan.directly_modified == {seed_model_snapshot.snapshot_id}
29382948
assert len(plan.missing_intervals) == 1
29392949
assert plan.missing_intervals[0].snapshot_id == seed_model_snapshot.snapshot_id
2940-
29412950
context.apply(plan)
29422951

2943-
actual_seed_df = context.fetchdf("SELECT * FROM sushi.waiter_names WHERE id = 123")
2944-
assert actual_seed_df.to_dict("records") == [
2945-
{
2946-
"id": 123,
2947-
"name": "New Test Name",
2948-
}
2949-
]
2952+
actual_seed_df_in_prod = context.fetchdf("SELECT * FROM sushi.waiter_names WHERE id = 123")
2953+
assert actual_seed_df_in_prod.to_dict("records") == [{"id": 123, "name": "New Test Name"}]
29502954

29512955

29522956
@time_machine.travel("2023-01-08 15:00:00 UTC")

0 commit comments

Comments
 (0)