Skip to content

Commit 14d63c2

Browse files
committed
Remove unused variable, fix test
1 parent 4df70be commit 14d63c2

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

sqlmesh/core/context.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,9 +2337,7 @@ def _run_janitor(self, ignore_ttl: bool = False) -> None:
23372337
# Clean up expired environments by removing their views and schemas
23382338
self._cleanup_environments()
23392339

2340-
expired_snapshot_ids, cleanup_targets = self.state_sync.get_expired_snapshots(
2341-
ignore_ttl=ignore_ttl
2342-
)
2340+
_, cleanup_targets = self.state_sync.get_expired_snapshots(ignore_ttl=ignore_ttl)
23432341

23442342
# Remove the expired snapshots tables
23452343
self.snapshot_evaluator.cleanup(

tests/core/test_context.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from sqlmesh.utils.date import (
4444
make_inclusive_end,
4545
now,
46+
now_timestamp,
4647
to_date,
4748
to_timestamp,
4849
yesterday_ds,
@@ -775,29 +776,40 @@ def test_janitor(sushi_context, mocker: MockerFixture) -> None:
775776
adapter_mock.dialect = "duckdb"
776777
state_sync_mock = mocker.MagicMock()
777778

778-
state_sync_mock.delete_expired_environments.return_value = [
779-
Environment(
780-
name="test_environment",
781-
suffix_target=EnvironmentSuffixTarget.TABLE,
782-
snapshots=[x.table_info for x in sushi_context.snapshots.values()],
783-
start_at="2022-01-01",
784-
end_at="2022-01-01",
785-
plan_id="test_plan_id",
786-
previous_plan_id="test_plan_id",
787-
),
788-
Environment(
789-
name="test_environment",
790-
suffix_target=EnvironmentSuffixTarget.SCHEMA,
791-
snapshots=[x.table_info for x in sushi_context.snapshots.values()],
792-
start_at="2022-01-01",
793-
end_at="2022-01-01",
794-
plan_id="test_plan_id",
795-
previous_plan_id="test_plan_id",
796-
),
797-
]
779+
now_ts = now_timestamp()
780+
filter_expr = exp.LTE(
781+
this=exp.column("expiration_ts"),
782+
expression=exp.Literal.number(now_ts),
783+
)
784+
785+
state_sync_mock.get_expired_environments.return_value = (
786+
[
787+
Environment(
788+
name="test_environment",
789+
suffix_target=EnvironmentSuffixTarget.TABLE,
790+
snapshots=[x.table_info for x in sushi_context.snapshots.values()],
791+
start_at="2022-01-01",
792+
end_at="2022-01-01",
793+
plan_id="test_plan_id",
794+
previous_plan_id="test_plan_id",
795+
),
796+
Environment(
797+
name="test_environment",
798+
suffix_target=EnvironmentSuffixTarget.SCHEMA,
799+
snapshots=[x.table_info for x in sushi_context.snapshots.values()],
800+
start_at="2022-01-01",
801+
end_at="2022-01-01",
802+
plan_id="test_plan_id",
803+
previous_plan_id="test_plan_id",
804+
),
805+
],
806+
filter_expr,
807+
)
798808

799809
sushi_context._engine_adapters = {sushi_context.config.default_gateway: adapter_mock}
800810
sushi_context._state_sync = state_sync_mock
811+
state_sync_mock.get_expired_snapshots.return_value = (set({}), [])
812+
801813
sushi_context._run_janitor()
802814
# Assert that the schemas are dropped just twice for the schema based environment
803815
# Make sure that external model schemas/tables are not dropped

0 commit comments

Comments
 (0)