Skip to content

Fall back when sqlite cache is unavailable#21443

Open
cyphercodes wants to merge 3 commits intopython:masterfrom
cyphercodes:cyphercodes/fix-21440-sqlite-cache-fallback
Open

Fall back when sqlite cache is unavailable#21443
cyphercodes wants to merge 3 commits intopython:masterfrom
cyphercodes:cyphercodes/fix-21440-sqlite-cache-fallback

Conversation

@cyphercodes
Copy link
Copy Markdown

Fixes #21440

When the sqlite cache is enabled but the sqlite3 module cannot import (for example when CPython was built without _sqlite3), fall back to the filesystem metadata cache instead of crashing during metastore creation.

Tests:

  • python3 -m pytest -q mypy/test/testmetastore.py
  • python3 -m mypy --config-file mypy_self_check.ini mypy/build.py mypy/test/testmetastore.py
  • pre-commit run --files mypy/build.py mypy/test/testmetastore.py
  • git diff --check

@github-actions

This comment has been minimized.

@cyphercodes
Copy link
Copy Markdown
Author

Updated this PR to make the sqlite fallback regression test work under mypyc-compiled CI.

Root cause: the test patched mypy.metastore.connect_db, which is not reliable in the mypyc-compiled test job, so the sqlite store was still constructed. The test now patches mypy.build.SqliteMetadataStore directly to raise ModuleNotFoundError, exercising the fallback path without depending on patching internals of a compiled module.

Local verification:

  • python3 -m pytest mypy/test/testmetastore.py -q
  • git diff --check

@github-actions

This comment has been minimized.

@cyphercodes
Copy link
Copy Markdown
Author

Follow-up: the first test-only fix still failed in mypyc-compiled jobs because unittest.mock.patch does not reliably replace compiled mypy globals there. I pushed a second small test-only commit that skips this mock-based unit test for compiled mypy, matching the existing pattern used elsewhere in the test suite for source-only assertions.

Local verification:

  • python3 -m pytest mypy/test/testmetastore.py -q
  • git diff --check

CI has restarted on commit 1244b63.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

Default mypy configuration crashes on python build without sqlite

1 participant