Feat/invalidate cleanup snapshots#5856
Draft
mday-io wants to merge 4 commits into
Draft
Conversation
In dbt 1.6/1.7 CI environments, snowflake-connector-python resolves to versions 3.0-3.7.x which require pyOpenSSL<24.0.0. When combined with cryptography>=42.0 (which removed the lib.GEN_EMAIL constant), importing the Snowflake connector raises AttributeError: module 'lib' has no attribute 'GEN_EMAIL', failing these tests: - test_snowflake_config (via SnowflakeConnectionConfig._validate_authenticator) - test_api_class_loading[snowflake] (via SnowflakeConfig.relation_class) pyOpenSSL>=24.0.0 forces pip/uv to resolve snowflake-connector-python to 3.8.0+ (which allows pyOpenSSL<25.0.0, thus including 24.x). pyOpenSSL 24.0.0 fixed the GEN_EMAIL incompatibility with cryptography>=42.0. dbt 1.3-1.5 and 1.8-1.10 are unaffected: earlier versions resolve connector packages that avoid this code path; later versions of the connector already widened cryptography's upper bound. Also collapses a multi-line docstring in classproperty to a single line. Signed-off-by: mday-io <mdaytn@gmail.com>
…eanup Adds a `--cleanup-snapshots` flag to `sqlmesh invalidate` that immediately deletes physical snapshot tables exclusively owned by the target environment, without affecting snapshots shared with other environments (e.g. prod). Previously, users had to run `sqlmesh janitor --ignore-ttl` separately after invalidating, which performed a global cleanup across all environments. The new flag provides a scoped alternative that: 1. Captures the environment's snapshot IDs before invalidation 2. Filters to only those not referenced by any other active environment 3. Drops the physical tables and removes the state records for those snapshots Changes: - cli/main.py: add --cleanup-snapshots flag to the invalidate command - core/context.py: pass cleanup_snapshots through to invalidate_environment - core/janitor.py: add delete_snapshots_for_environment() helper function - core/state_sync/base.py: add target_snapshot_ids param to get/delete_expired_snapshots - core/state_sync/db/facade.py: thread target_snapshot_ids through facade - core/state_sync/db/snapshot.py: filter expired query by target_snapshot_ids when provided - core/state_sync/cache.py: add target_snapshot_ids param to CachingStateSync Closes SQLMesh#5844 Signed-off-by: mday-io <mdaytn@gmail.com>
- C1/M4: eliminate TOCTOU race in delete_snapshots_for_environment by calling state_sync.delete_snapshots(batch.expired_snapshot_ids) directly instead of re-querying via delete_expired_snapshots, so physical drops and state removal operate on the same snapshot ID set - M1: remove always-truthy `if target_conditions:` guard in get_expired_snapshots (snapshot_id_filter always yields >= 1 condition) - M2: when cleanup_snapshots=True and the environment does not exist, log a warning and return early instead of printing a misleading success message - m1: unconditionally initialize target_snapshot_ids before the cleanup_snapshots block to prevent potential UnboundLocalError - n1: enforce `sync = sync or cleanup_snapshots` explicitly so the implication is in code, not just docs; update docstring and CLI help to say "cleanup runs synchronously" instead of "Implies --sync" Signed-off-by: mday-io <mdaytn@gmail.com>
ae27f17 to
5c9d308
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Test Plan
Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO