Skip to content

fix(ci): tomllib is not stdlib below Python 3.11, but the test matrix runs 3.9 - #55

Open
yakimoto wants to merge 1 commit into
mainfrom
fix/tomllib-py39-fallback
Open

fix(ci): tomllib is not stdlib below Python 3.11, but the test matrix runs 3.9#55
yakimoto wants to merge 1 commit into
mainfrom
fix/tomllib-py39-fallback

Conversation

@yakimoto

@yakimoto yakimoto commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

User description

What

pytest collection failed on the Python 3.9 leg of python-tests.yml with:

ModuleNotFoundError: No module named 'tomllib'

for both tests/test_check_drift.py and tests/test_ga_common_github_auth.py, interrupting the whole run on that matrix leg (2 errors during collection, 0 tests executed).

Root cause

tomllib is Python stdlib only from 3.11. This package declares requires-python = ">=3.9" and python-tests.yml's matrix is ["3.9", "3.12", "3.13"] — deliberately added so a version that can install the wheel is also a version whose behavior is asserted. pytest collects every test file in the run regardless of which one is under test, so any file that imports a module doing import tomllib unconditionally breaks collection for the entire 3.9 leg, not just its own tests.

Two release-tooling modules had this: scripts/release/check_drift.py and scripts/ga/ga_common.py. Both did import tomllib unconditionally, even though pyproject.toml already declares "tomli>=2.0.0; python_version < '3.11'" as a dev extra specifically for this case, and tests/test_packaging.py already carries the correct fallback pattern (comment: "tomllib is stdlib from 3.11 only"). These two modules were simply never updated to match.

Fix

Applied the exact same, already-established pattern from tests/test_packaging.py to both modules:

try:  # tomllib is stdlib from 3.11; `tomli` is a dev dependency below that (see pyproject.toml).
    import tomllib
except ModuleNotFoundError:
    import tomli as tomllib

Also updated check_drift.py's module docstring, which claimed "Python 3.11+ ... required" — that was never actually a hard requirement given the tomli extra, and the CI matrix now proves it isn't.

Verification

  • python3 -m py_compile on both changed files: clean.
  • Simulated ModuleNotFoundError for tomllib via a monkeypatched __import__ and imported check_drift fresh: it fell through to tomli correctly (check_drift.tomllib resolved to the tomli module object).
  • python3 -m pytest -q tests/test_check_drift.py tests/test_ga_common_github_auth.py: 13 passed, 0 failed (run on the locally available Python 3.14, which already had tomllib; the fallback path itself was proven separately above since no 3.9 interpreter was available in this environment).
  • No 3.9 interpreter was available in the sandbox this fix was authored in, so the CI matrix itself is the first real 3.9 execution — the change is a minimal, mechanical mirror of test_packaging.py's already-shipped and already-tested pattern, not new untested logic.

Scope

Two files touched, both additive (a try/except ModuleNotFoundError wrapper around an existing single-line import, plus one docstring correction). No test was weakened, skipped, or had an assertion loosened — this fixes test collection, which is a strict net-positive for coverage (0 tests running on 3.9 -> all tests running on 3.9).

Context

This was investigated as part of a fleet-wide sweep for CI failures across the ~32 WAVE public repos. Measuring gh run list --branch main across every public repo found that only this repo had a genuine current failure on its default branch. sdks' concurrent registry clean-room acceptance failures had already self-resolved (green as of the latest run) before this sweep started. This fix addresses the one real, currently-reproducing failure found, with its own distinct root cause (a Python stdlib version gate, unrelated to any Node/npm NODE_ENV install-skip pattern floated as a leading hypothesis for a fleet-wide story).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Additive import compatibility only; no logic or assertion changes beyond enabling the 3.9 CI matrix leg to collect and run tests.

Overview
Fixes pytest collection on Python 3.9 by stopping unconditional import tomllib in scripts/ga/ga_common.py and scripts/release/check_drift.py. Both now use the same try stdlib tomllib / except tomli as tomllib pattern already used elsewhere in the repo, aligned with the existing tomli dev extra for python_version < '3.11'.

check_drift.py's module docstring is updated to describe 3.9+ support (via tomli) instead of implying Python 3.11+ only. Behavior for reading pyproject.toml is unchanged on 3.11+; on 3.9–3.10 imports no longer fail at module load time.

Reviewed by Cursor Bugbot for commit 62f8706. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by Sourcery

Support TOML parsing across all supported Python versions so the complete test suite can run on Python 3.9.

Bug Fixes:

  • Restore Python 3.9 CI test collection by falling back to the supported tomli package when tomllib is unavailable.

Enhancements:

  • Update release tooling documentation to reflect support across the package’s Python 3.9+ compatibility matrix.

Review in cubic


CodeAnt-AI Description

Restore Python 3.9 compatibility for release tooling

What Changed

  • Release and GA tooling now reads project metadata on Python versions below 3.11 using the supported TOML compatibility package
  • Python 3.9 test collection no longer fails when these modules are imported
  • Documentation now reflects support for the full Python 3.9+ compatibility range

Impact

✅ Passing Python 3.9 test runs
✅ Fewer CI collection failures
✅ Release checks work across supported Python versions

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

… runs 3.9

python-tests.yml added a pytest matrix of 3.9/3.12/3.13, and pytest collects
every test file regardless of which one is under test. tests/test_check_drift.py
and tests/test_ga_common_github_auth.py both import (directly or transitively)
scripts/release/check_drift.py and scripts/ga/ga_common.py, both of which did
`import tomllib` unconditionally — a module stdlib only from Python 3.11.
Collection failed with ModuleNotFoundError on the 3.9 leg, interrupting the
whole run (2 errors during collection, 0 tests executed on that leg).

pyproject.toml already declares `tomli>=2.0.0; python_version < '3.11'` as a
dev dependency, and tests/test_packaging.py already uses the
try/except ModuleNotFoundError fallback — this applies the same, already-
established pattern to the two release-tooling modules that were missing it.
@yakimoto yakimoto added the rr:unrationed RF.P1 reviewer routing (#1039) label Sep 8, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @yakimoto, this account has used its review budget of 2,500,000 diff characters for the last 7 days.

You can request another review in 1 day and 3 hours by commenting @sourcery-ai review.

@codeant-ai

codeant-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 62f8706 Sep 08, 2026 · 22:14 22:16

@codeant-ai

codeant-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@cursor

cursor Bot commented Sep 8, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_8b8af8c1-5f04-47fe-8b0f-d8b8af795521)

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes Python 3.9 test collection failures by making both release-tooling modules use tomli when tomllib is unavailable, while correcting documentation that incorrectly implied Python 3.11+ was required.

Flow diagram for Python-version-compatible TOML loading

flowchart TD
    Import["Release tooling imports TOML parser"] --> Available{"tomllib available?"}
    Available -->|Yes| Stdlib["Use stdlib tomllib"]
    Available -->|No: Python below 3.11| Fallback["Use dev dependency tomli as tomllib"]
    Stdlib --> Continue["Module loads and pytest collection continues"]
    Fallback --> Continue
Loading

File-Level Changes

Change Details Files
Add a Python-version-compatible TOML import fallback for release and GitHub Actions tooling.
  • Wrap the stdlib tomllib import and fall back to the declared tomli dev dependency on Python versions below 3.11.
  • Apply the same established fallback pattern used by the packaging tests.
  • Update the module documentation to describe support across the package’s Python >=3.9 matrix.
scripts/ga/ga_common.py
scripts/release/check_drift.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Sep 8, 2026
@gitar-bot

gitar-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

Note

Automatic reviews are paused because your team has used its included automatic processing for this billing period (headroom scales with your seat count). You can still comment "Gitar review" to run one anytime, and automatic reviews resume on their own by October 1. Add seats for more headroom.
Learn more

Code Review ✅ Approved

Fixes pytest collection failure on Python 3.9 by adding tomllib/tomli fallback imports to scripts/release/check_drift.py and scripts/ga/ga_common.py, matching the established pattern already used in tests/test_packaging.py. Updates check_drift.py's module docstring to reflect Python 3.9+ support. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 366c7074-602a-44d2-893a-0223341c7a0b

📥 Commits

Reviewing files that changed from the base of the PR and between 8072175 and 62f8706.

📒 Files selected for processing (2)
  • scripts/ga/ga_common.py
  • scripts/release/check_drift.py

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
scripts/ga/ga_common.py (1)

20-23: LGTM!

scripts/release/check_drift.py (1)

29-31: LGTM!

Also applies to: 44-47


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility for Python 3.9 and 3.10 when reading project configuration files.
    • Release validation now works consistently across supported Python versions.
  • Documentation

    • Updated release-checking guidance to reflect supported Python versions and configuration parsing requirements.

Walkthrough

The scripts now support TOML parsing on Python 3.9–3.10 by using tomli when tomllib is unavailable. The release script documentation describes this compatibility behavior.

Changes

TOML compatibility

Layer / File(s) Summary
TOML import fallback
scripts/ga/ga_common.py, scripts/release/check_drift.py
Both scripts prefer stdlib tomllib and fall back to tomli on older Python versions. The release script documents support for the Python 3.9+ matrix.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 62f87

The release and GA scripts can now parse TOML on Python 3.9–3.10 while retaining the standard-library parser on newer Python versions. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the Python 3.9 CI failure and the missing stdlib compatibility for tomllib. It matches the main change.
Description check ✅ Passed The description directly explains the Python 3.9 collection failure, its root cause, the tomli fallback, verification, and scope of the changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tomllib-py39-fallback
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/tomllib-py39-fallback

Comment @coderabbitai help to get the list of available commands.

@macroscopeapp

macroscopeapp Bot commented Sep 8, 2026

Copy link
Copy Markdown

Approvability

Verdict: Would Approve

Macroscope's review found this PR approvable — This is a narrowly scoped CI compatibility fix that lets existing GA and release checks run on Python 3.9–3.10 using the already-declared tomli development dependency. It does not alter the shipped SDK or customer request paths.

Not approved because:

  • Credit balance exhausted. Approvability relies on correctness review in order to determine eligibility

Review your spending limits in Billing settings. You can add or adjust custom eligibility rules. Learn more.

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your workspace is out of credits. Ask your workspace admin to add credits to resume reviews. Manage billing

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant CI as CI Runner (python-tests matrix)
    participant Py as Python Interpreter
    participant Module as Changed Scripts (ga_common.py / check_drift.py)
    participant TomlLib as tomllib (stdlib 3.11+)
    participant Tomli as tomli (fallback < 3.11)
    participant DevExtra as pyproject.toml dev dependency
    participant Pkg as Package metadata (pyproject.toml)
    participant TestFile as Test Files

    Note over CI,TestFile: Python 3.9-3.10 execution path
    
    CI->>Py: Initialize Python 3.9
    Py->>TestFile: Collect test files
    TestFile->>Module: Import module for collection
    
    Module->>Module: Attempt import tomllib
    Module->>TomlLib: import tomllib
    
    alt Python 3.11+ (tomllib available)
        TomlLib-->>Module: Module loaded successfully
    else Python 3.9-3.10 (ModuleNotFoundError)
        TomlLib-->>Module: ModuleNotFoundError raised
        Module->>DevExtra: Check dev dependency availability
        DevExtra->>Tomli: tomli installed via dev extra
        Module->>Tomli: import tomli as tomllib
        Tomli-->>Module: Module loaded as fallback
    end
    
    Module->>Pkg: Parse pyproject.toml metadata
    Pkg-->>Module: Return package configuration
    Module-->>TestFile: Import successful, tests can run
    
    Note over CI,TestFile: Debug/git operations in check_drift.py
    Module->>Module: git/gh CLI operations for drift checking
    Module-->>TestFile: Check drift results
    
    Note over CI,TestFile: New behavior validated
    CI->>Py: All tests in matrix leg execute
    Py-->>CI: Test results (pass/fail)

    Note over Module,Tomli: Key architectural boundary
    Note over Module,Tomli: TOML parsing abstraction layer
    Note over Module,Tomli: Same interface via alias, different backends
Loading

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rr:unrationed RF.P1 reviewer routing (#1039) size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant