Skip to content

gh-158998: Fix os.statx() ignoring follow_symlinks=False - #158999

Open
jjhelmus wants to merge 4 commits into
python:mainfrom
jjhelmus:statx-follow-symlinks
Open

jjhelmus wants to merge 4 commits into
python:mainfrom
jjhelmus:statx-follow-symlinks

Conversation

@jjhelmus

@jjhelmus jjhelmus commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Set AT_SYMLINK_NOFOLLOW to prevent statx from following symlinks when follow_symlinks=False is passed to os.statx.

@jjhelmus

jjhelmus commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Let me know if this change meet the criteria for needing tests or a NEWS item. I can add both if needed.

@cmaloney

cmaloney commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This will need both NEWS and a test (changes visible behavior of a feature that has been in a release). Pinged the contributor who added statx to hopefully review (haven’t reviewed the implementation myself yet)

@jbosboom

jbosboom commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

The fix looks obviously correct. (Whoops!)

The tests should go in test_os.StatAttributeTests. Change check_statx_attributes to accept a follow_symlinks kwarg and pass it to the os.stat and os.statx calls, then add new test methods like test_statx_attributes that create a proper/broken symlink and pass follow_symlinks=False/True (four cases; can be four methods or one method with four subtests).

Ping me again for review when you've written the tests.

@jjhelmus

jjhelmus commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

I've added a the described tests and a NEWS item. @jbosboom was this what you were looking for in the tests?

@cmaloney cmaloney added the needs backport to 3.15 bugs and security fixes label Oct 8, 2026
# break the symlink
os.unlink(self.fname)
with self.subTest(broken=True, follow_symlinks=True):
with self.assertRaises(FileNotFoundError):

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.

check_statx_attributes only accidentally checks that os.statx raises in this case (because os.statx is called before os.stat). I think it's sufficient and clearer to call os.statx directly here.

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.

I mean: replace self.check_statx_attributes -> os.statx on the line just after the lines shown in the comment. (Sorry, not used to GitHub's review/comment interface.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed that calling statx here is clearer. I've updated the test.

@jbosboom

jbosboom commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

LGTM except for one comment on the test, where you did what I asked for even though it doesn't make sense in one case.

Thanks for fixing this, and I'm sorry you had to fix it.

@jjhelmus

jjhelmus commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for fixing this, and I'm sorry you had to fix it.

Happy to address this.
I discovered this when putting together the more ambitious syscall fallback for statx, #159043, which effects similar areas blocks.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants