Skip to content

Conversation

@johnslavik
Copy link
Contributor

@johnslavik johnslavik commented Dec 7, 2025

Oh the irony that this was never a real path.

I need to figure out how to test this -- it's a regression, after all, so no excuses this time.

CC @ZeroIntensity needs backport to 3.13, needs backport to 3.14

@johnslavik johnslavik marked this pull request as draft December 7, 2025 01:41
@johnslavik johnslavik changed the title Don't pass the "real path" of Pdb script target to system functions gh-142315: Don't pass the "real path" of Pdb script target to system functions Dec 7, 2025
@ZeroIntensity ZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Dec 7, 2025
@johnslavik
Copy link
Contributor Author

I need to figure out how to test this -- it's a regression, after all, so no excuses this time.

Or... maybe I just mention the issue in a comment above the affected lines -- this will be my escape hatch to not write tests 💡

@johnslavik johnslavik force-pushed the pdb-realpath-pseudofs-problem branch 2 times, most recently from ac11ff4 to 682069d Compare December 7, 2025 13:26
@johnslavik johnslavik force-pushed the pdb-realpath-pseudofs-problem branch from 682069d to 7050770 Compare December 7, 2025 13:26
@johnslavik
Copy link
Contributor Author

Ok, this one is clean and works!

@johnslavik johnslavik marked this pull request as ready for review December 7, 2025 13:28
@johnslavik johnslavik force-pushed the pdb-realpath-pseudofs-problem branch from 7767efa to d9932f5 Compare December 7, 2025 13:35
@jaraco
Copy link
Member

jaraco commented Dec 7, 2025

Thanks for the contrib!

I need to figure out how to test this -- it's a regression, after all, so no excuses this time.

Or... maybe I just mention the issue in a comment above the affected lines -- this will be my escape hatch to not write tests 💡

My preference would be to create a regression test. It seems it shouldn't be too hard to create or identify a pseudofs object to pass in and catch the SystemExit. I'll work on one.

I saw in email that @johnslavik did some analysis on the root cause in readpath/readlink. It'd be nice to get that published somewhere. Even if there's nothing wrong with Python's wrapper around realpath, it may still be worth filing an issue to capture the investigation and consider updating the docs to flag this potential issue.

self._target = os.path.realpath(target)

if not os.path.exists(self._target):
if not os.path.exists(target):
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking we should have a one-line change in the constructor, something like:

Suggested change
if not os.path.exists(target):
self._target = self._safe_realpath(target)
if not os.path.exists(self._target):

Then, _safe_realpath would have the logic and a docstring instead of a comment describing why it exists and how it protects against non-existent readlink targets (the code below).

Copy link
Contributor Author

@johnslavik johnslavik Dec 7, 2025

Choose a reason for hiding this comment

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

And maybe it will help with the test, yeah :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm worried safe_realpath could be confusing near the current safe_path(-P) comment. I'll fixup that comment to reduce confusion.

Copy link
Contributor Author

@johnslavik johnslavik Dec 7, 2025

Choose a reason for hiding this comment

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

#142371 (comment)

@jaraco To not change the behavior out of scope of the issue, I'd have to keep the file existence validation invoked prior to calling _safe_realpath anyway. os.path.realpath does suppress OSError, but I'd not mess with that if we can avoid double-checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change done.

@jaraco
Copy link
Member

jaraco commented Dec 7, 2025

I've created #142383 with a test. Assuming that test is failing as expected, I'll try merging it with this fix.

@johnslavik johnslavik force-pushed the pdb-realpath-pseudofs-problem branch from 60aa009 to e42ba5e Compare December 7, 2025 18:24
@johnslavik johnslavik force-pushed the pdb-realpath-pseudofs-problem branch from e42ba5e to 5b12904 Compare December 7, 2025 18:25
@johnslavik
Copy link
Contributor Author

I think I like it the way it is now. It's a problem of maintaining the equivalence invariant -- easy to follow.

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

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants