-
Notifications
You must be signed in to change notification settings - Fork 358
fix!: correctly identify keys to make deterministic #4984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import json | ||
| import logging | ||
|
|
||
| from sqlglot import exp | ||
|
|
||
| from sqlmesh.core.console import get_console | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
| KEYS_TO_MAKE_DETERMINISTIC = ["__sqlmesh__vars__", "__sqlmesh__blueprint__vars__"] | ||
|
|
||
|
|
||
| def migrate(state_sync, **kwargs): # type: ignore | ||
| engine_adapter = state_sync.engine_adapter | ||
| schema = state_sync.schema | ||
| snapshots_table = "_snapshots" | ||
| versions_table = "_versions" | ||
| if schema: | ||
| snapshots_table = f"{schema}.{snapshots_table}" | ||
| versions_table = f"{schema}.{versions_table}" | ||
|
|
||
| result = engine_adapter.fetchone( | ||
| exp.select("schema_version").from_(versions_table), quote_identifiers=True | ||
| ) | ||
| if not result: | ||
| # This must be the first migration, so we can skip the check since the project was not exposed to 85 migration bug | ||
| return | ||
| schema_version = result[0] | ||
| if schema_version < 85: | ||
| # The project was not exposed to the bugged 85 migration, so we can skip it. | ||
| return | ||
|
|
||
| warning = ( | ||
| "SQLMesh detected that it may not be able to fully migrate the state database. This should not impact " | ||
| "the migration process, but may result in unexpected changes being reported by the next `sqlmesh plan` " | ||
| "command. Please run `sqlmesh diff prod` after the migration has completed, before making any new " | ||
| "changes. If any unexpected changes are reported, consider running a forward-only plan to apply these " | ||
| "changes and avoid unnecessary backfills: sqlmesh plan prod --forward-only. " | ||
| "See https://sqlmesh.readthedocs.io/en/stable/concepts/plans/#forward-only-plans for more details.\n" | ||
| ) | ||
|
|
||
| for ( | ||
| name, | ||
| identifier, | ||
| version, | ||
| snapshot, | ||
| kind_name, | ||
| updated_ts, | ||
| unpaused_ts, | ||
| ttl_ms, | ||
| unrestorable, | ||
| ) in engine_adapter.fetchall( | ||
| exp.select( | ||
| "name", | ||
| "identifier", | ||
| "version", | ||
| "snapshot", | ||
| "kind_name", | ||
| "updated_ts", | ||
| "unpaused_ts", | ||
| "ttl_ms", | ||
| "unrestorable", | ||
| ).from_(snapshots_table), | ||
| quote_identifiers=True, | ||
| ): | ||
| parsed_snapshot = json.loads(snapshot) | ||
| python_env = parsed_snapshot["node"].get("python_env") | ||
|
|
||
| if python_env: | ||
| for key, executable in python_env.items(): | ||
| if ( | ||
| key not in KEYS_TO_MAKE_DETERMINISTIC | ||
| and isinstance(executable, dict) | ||
| and executable.get("kind") == "value" | ||
| ): | ||
| try: | ||
| parsed_value = eval(executable["payload"]) | ||
| if isinstance(parsed_value, dict): | ||
| get_console().log_warning(warning) | ||
| return | ||
| except Exception: | ||
| logger.warning("Exception trying to eval payload", exc_info=True) |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.