-
Notifications
You must be signed in to change notification settings - Fork 119
SG-43269 Improve core swap diagnostics with version mismatch detection #1099
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
Open
carlos-villavicencio-adsk
wants to merge
6
commits into
master
Choose a base branch
from
ticket/SG-43269_core_backwards_compatibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91d5bde
Validate core swap version mismatch and provide logs
carlos-villavicencio-adsk 09a8233
Add exception class
carlos-villavicencio-adsk a7963be
Add tests
carlos-villavicencio-adsk c7f0956
Fix test
carlos-villavicencio-adsk 1117e6f
Improve UI error display
carlos-villavicencio-adsk 999312e
Fix tests
carlos-villavicencio-adsk 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import warnings | ||
|
|
||
| from .. import LogManager | ||
| from .. import pipelineconfig_utils | ||
|
|
||
| log = LogManager.get_logger(__name__) | ||
|
|
||
|
|
@@ -49,8 +50,16 @@ def swap_core(cls, core_path): | |
| """ | ||
| # make sure handler is up | ||
| handler = cls._initialize() | ||
| handler_core_version = pipelineconfig_utils.get_currently_running_api_version() | ||
|
|
||
| log.debug("%s: Begin swapping core to %s" % (handler, core_path)) | ||
| target_core_version = pipelineconfig_utils.get_core_api_version( | ||
| os.path.dirname(os.path.dirname(os.path.dirname(core_path))) | ||
| ) | ||
|
|
||
| log.debug( | ||
| "%s (version %s): Begin swapping core to %s (version %s)" | ||
| % (handler, handler_core_version, core_path, target_core_version) | ||
| ) | ||
|
|
||
| # swapping core means our logging singleton will be reset. | ||
| # make sure that there are no log handlers registered | ||
|
|
@@ -91,6 +100,21 @@ def swap_core(cls, core_path): | |
| # Kick toolkit to re-import | ||
| import tank | ||
|
|
||
| except Exception: | ||
| # If anything happens here, log an error and continue. | ||
| # Check the core versions handler_core_version and target_core_version, | ||
| # There might be a breaking change between the two versions. | ||
| if pipelineconfig_utils.is_version_older( | ||
| target_core_version, handler_core_version | ||
| ): | ||
| error_message = ( | ||
| f"Core version mismatch: {target_core_version} might be older than" | ||
| f" {handler_core_version}. Please check the release notes for breaking" | ||
| f" changes: https://github.com/shotgunsoftware/tk-core/releases" | ||
| ) | ||
| log.error(error_message) | ||
| raise ImportError(error_message) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ the |
||
|
|
||
| finally: | ||
| # Restore the list of warning filters. | ||
| warnings.filters = original_filters | ||
|
|
@@ -289,20 +313,14 @@ def find_spec(self, module_fullname, package_path=None, target=None): | |
| # later raise FileNotFoundError instead of the expected ImportError | ||
| # when the module doesn't exist on disk. | ||
| if os.path.isdir(os.path.join(package_path[0], module_name)): | ||
| module_file = os.path.join( | ||
| package_path[0], module_name, "__init__.py" | ||
| ) | ||
| module_file = os.path.join(package_path[0], module_name, "__init__.py") | ||
| else: | ||
| module_file = os.path.join( | ||
| package_path[0], module_name + ".py" | ||
| ) | ||
| module_file = os.path.join(package_path[0], module_name + ".py") | ||
|
|
||
| if not os.path.isfile(module_file): | ||
| return None | ||
|
|
||
| loader = importlib.machinery.SourceFileLoader( | ||
| module_fullname, module_file | ||
| ) | ||
| loader = importlib.machinery.SourceFileLoader(module_fullname, module_file) | ||
| spec = importlib.util.spec_from_loader(loader.name, loader) | ||
| self._module_info[module_fullname] = spec | ||
| except ImportError: | ||
|
|
@@ -328,9 +346,7 @@ def load_module(self, module_fullname): | |
| try: | ||
| spec.loader.exec_module(module) | ||
| except FileNotFoundError as e: | ||
| raise ImportError( | ||
| f"No module named '{module_fullname}'" | ||
| ) from e | ||
| raise ImportError(f"No module named '{module_fullname}'") from e | ||
|
|
||
| # the module needs to know the loader so that reload() works | ||
| module.__loader__ = self | ||
|
|
||
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
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.