Skip to content

Fix crash when checking file in a read only directory#21496

Open
karlicoss wants to merge 2 commits into
python:masterfrom
karlicoss:fix/sqlite-store-readonly
Open

Fix crash when checking file in a read only directory#21496
karlicoss wants to merge 2 commits into
python:masterfrom
karlicoss:fix/sqlite-store-readonly

Conversation

@karlicoss
Copy link
Copy Markdown

@karlicoss karlicoss commented May 16, 2026

Only applies to new SqliteMetadataStore, which is the default since 1.20; old FilesystemMetadataStore doesn't crash.

Fixes #21495


I added a test for SqliteMetadataStore -- a bit surprised there weren't any in the first place, perhaps the idea is that this is already covered by cmdline based integration tests? I had a stab at implementing one for consistency, but realized that there is no way to issue a chmod -w there, so figured a more specialized unit test is fine. Let me know if there is a better way to test this!


Disclosing the use of LLMs in pull request description is recommended, but not required.

I used Claude to bisect when issue started happening and to suggest me best place to place code and make it consistent with existing testbase; but otherwise fully understand it!

Only applies to new SqliteMetadataStore, which is the default since
1.20; old FilesystemMetadataStore doesn't crash.

Fixes python#21495

@unittest.skipIf(
sys.platform == "win32",
"POSIX chmod semantics: os.chmod(dir, 0o555) does not prevent writes on Windows",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Wasn't sure what's better -- excluding test altogether, or checking the same thing after store = SqliteMetadataStore(cache_dir) and returning early/skipping in the test body.

I figured excluding it altogether is less confusing.

Comment thread mypy/metastore.py
os.makedirs(cache_dir_prefix, exist_ok=True)
try:
os.makedirs(cache_dir_prefix, exist_ok=True)
except OSError:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Perhaps a bit too broad, but catching all sort of possible FS read-only states can be difficult, and also this is consistent with what FilesystemMetadataStore was doing..

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

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.

crash when type checking file in a read only directory

1 participant