Skip to content

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

Merged
StanFromIreland merged 4 commits into
python:mainfrom
jjhelmus:statx-follow-symlinks
Oct 31, 2026
Merged

StanFromIreland merged 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
Comment thread Lib/test/test_os/test_os.py Resolved
@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.

@StanFromIreland StanFromIreland changed the title gh-158998: Fix os.statx() ignoring follow_symlinks=False Oct 31, 2026
@StanFromIreland
StanFromIreland merged commit b84e0b7 into python:main Oct 31, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @jjhelmus for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

GH-160996 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 31, 2026
@StanFromIreland

Copy link
Copy Markdown
Member

Merged, thanks.

StanFromIreland pushed a commit that referenced this pull request Oct 31, 2026
…H-158999) (#160996)

(cherry picked from commit b84e0b7)

Co-authored-by: Jonathan J. Helmus <jjhelmus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants