Skip to content

SG-44721 Fix tank core upgrade fails from ≤v0.23.6 to ≥v0.23.7 - #1127

Merged
julien-lang merged 1 commit into
masterfrom
ticket/SG-44721-fix-core-upgrader-yaml-import
Aug 17, 2026
Merged

SG-44721 Fix tank core upgrade fails from ≤v0.23.6 to ≥v0.23.7#1127
julien-lang merged 1 commit into
masterfrom
ticket/SG-44721-fix-core-upgrader-yaml-import

Conversation

@julien-lang

@julien-lang julien-lang commented Aug 7, 2026

Copy link
Copy Markdown
Member

tank core fails with ModuleNotFoundError: No module named 'yaml'.

Two related cases:

  1. Running _core_upgrader.py directly (e.g. python3 _core_upgrader.py) fails unconditionally on any version >= v0.23.7, including current master - there's no prior process state to mask it.
  2. Running the real tank core upgrade command fails specifically when the currently installed core is <= v0.23.6 and the target is >= v0.23.7. Upgrading between two cores that are both already >= v0.23.7 (or both <= v0.23.6) is unaffected - see Root Cause below for why.

Root cause

SG-37222 / #996 reworked tank_vendor third-party dependency handling starting in v0.23.7: vendored packages moved from flat files under python/tank_vendor/ into zip archives, loaded lazily through a sys.meta_path finder registered in tank_vendor/__init__.py.

_core_upgrader.py was never updated for this change. It still added python/tank_vendor directly to sys.path and did a bare import yaml, bypassing tank_vendor/__init__.py entirely, so the finder never registered and the flat yaml module it expected no longer existed on disk.

tank core runs as a single, uninterrupted Python process (the tank -> tank_cmd.sh -> exec $interpreter tank_cmd.py chain replaces the process in place, and the core swap is a plain import _core_upgrader within that process). The currently installed core's core_upgrade.py already does from tank_vendor import yaml before the swap. If that core is already >= v0.23.7, its vendor package's meta finder resolves this via __import__("yaml"), which as a side effect registers bare sys.modules["yaml"] - masking the target's broken bare import yaml entirely. If the installed core is <= v0.23.6, its pre-rework tank_vendor has no meta finder, so nothing gets cached, and the target's import yaml fails for real. This is why the bug only reproduces on the <=v0.23.6 -> >=v0.23.7 transition, even though the underlying defect is unconditional.

Fix

  • Add python/ (the parent of tank_vendor) to sys.path instead of tank_vendor itself.
  • Import via from tank_vendor import yaml so tank_vendor/__init__.py runs and registers its lazy-loading finder.
  • Use sys.path.insert(0, ...) instead of append for consistency with other core scripts.

Testing

  • Ran _core_upgrader.py directly; it no longer raises ModuleNotFoundError on import.
  • Confirmed the old code path fails the same way against current master's tank_vendor structure, matching the reported traceback.
  • QA reproduced a real tank core upgrade from v0.23.6 -> v0.24.0 failing without the fix and succeeding with it, and validated v0.23.7 -> v0.24.0 as well; dedicated core-upgrade regression coverage has been added.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a core-upgrade regression introduced after the tank_vendor dependency-loading overhaul (v0.23.7+), where _core_upgrader.py imported yaml in a way that bypassed tank_vendor/__init__.py, causing ModuleNotFoundError during tank core upgrades.

Changes:

  • Adds the local python/ folder (not python/tank_vendor/) to sys.path at position 0 so the bundled core code is preferred over any site-packages.
  • Switches from import yaml to from tank_vendor import yaml to ensure tank_vendor’s import hook is registered.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread _core_upgrader.py
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.11%. Comparing base (d4cd9de) to head (26bb764).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1127   +/-   ##
=======================================
  Coverage   80.11%   80.11%           
=======================================
  Files         203      203           
  Lines       19540    19540           
=======================================
  Hits        15654    15654           
  Misses       3886     3886           
Flag Coverage Δ
Linux 79.54% <ø> (ø)
Python-3.10 79.91% <ø> (ø)
Python-3.11 79.81% <ø> (ø)
Python-3.13 79.83% <ø> (+<0.01%) ⬆️
Python-3.9 79.88% <ø> (ø)
Windows 79.58% <ø> (ø)
macOS 79.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@julien-lang
julien-lang marked this pull request as ready for review August 7, 2026 13:51
@julien-lang
julien-lang requested a review from a team August 7, 2026 13:51

@chenm1adsk chenm1adsk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@julien-lang julien-lang changed the title SG-44721 Fix yaml import in _core_upgrader.py SG-44721 Fix tank core upgrade fails from ≤v0.23.6 to ≥v0.23.7 Aug 17, 2026
@julien-lang
julien-lang merged commit 0eb9405 into master Aug 17, 2026
29 checks passed
@julien-lang
julien-lang deleted the ticket/SG-44721-fix-core-upgrader-yaml-import branch August 17, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants