gh-142315: Don't pass the "real path" of Pdb script target to system functions#142371
gh-142315: Don't pass the "real path" of Pdb script target to system functions#142371jaraco merged 12 commits into
Conversation
Or... maybe I just mention the issue in a comment above the affected lines -- this will be my escape hatch to not write tests 💡 |
Sorry, something went wrong.
ac11ff4 to
682069d
Compare
December 7, 2025 13:26
682069d to
7050770
Compare
December 7, 2025 13:26
|
Ok, this one is clean and works! |
Sorry, something went wrong.
7767efa to
d9932f5
Compare
December 7, 2025 13:35
|
Thanks for the contrib!
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. |
Sorry, something went wrong.
|
I've created #142383 with a test. Assuming that test is failing as expected, I'll try merging it with this fix. |
Sorry, something went wrong.
60aa009 to
e42ba5e
Compare
December 7, 2025 18:24
e42ba5e to
5b12904
Compare
December 7, 2025 18:25
|
I think I like it the way it is now. It's a problem of maintaining the equivalence invariant -- easy to follow. |
Sorry, something went wrong.
264e306 to
4ca2bcf
Compare
December 7, 2025 20:25
We could; it's not obvious to me what is the best choice. I elected not to change the behavior from what was stable (and just surgically address the one edge case). What's the case for using |
Sorry, something went wrong.
I'm not aiming to display realpath in the message, but to display the same path that was checked, not something potentially different which can lead to a confusing or incorrect message. It was part of the report -- had the same target that was checked been used in the error message, it would have been much clearer what happened. I'm fine with not displaying realpath, but only provided that we don't check the realpath -- so, what we check and what we display is always the same (this is the most important to me, because only then the message is certainly correct). Apart from that,
The discrepancy between what is displayed and what is checked was introduced in GH-26992. |
Sorry, something went wrong.
|
Thanks for the explanation. I do agree, it's a little disorienting that the check is on one value but the error message reflects a different value. As you pointed out, GH-26992 originated this issue, and in that change, I explicitly attempted to avoid or to account for any meaningful changes to behavior. That included not changing the input path in the error message. I suspect it's important to the user that whatever they supplied as the script name is reflected in the error message (and not the realpath-mutated value). So maybe it makes sense to use If that's important, that aspect is not captured by a regression test. I think we need a regression test or at least a comment that captures this refined expectation. As I look at this further, I'm struggling to understand why the realpath issue didn't affect older Pythons.
Except it was. The mutation happened here, which was then passed to _runscript here, which is consumed here. I don't yet understand why the broken realpath didn't cause problems subsequently. |
Sorry, something went wrong.
…w no longer needed.
|
Oh! I see now. The use of realpath was introduced in #23338. That suggests that the proper fix may be to go back to that older behavior and narrow the use of realpath to the |
Sorry, something went wrong.
|
In 855aac3, I've isolated the realpath usage to the |
Sorry, something went wrong.
|
That doesn't work. It causes a regression in test_issue42383. |
Sorry, something went wrong.
…sage there." This reverts commit 855aac3.
Exactly.
Precisely.
Sure!
Thank you -- that's correct, I must have misread it. @jaraco Would the logic from 5b12904 suffice? I believe it passed all tests and it solved both problems, namely (1) potentially incorrect error message (2) support for live descriptors of internal kernel objects. |
Sorry, something went wrong.
|
@jaraco Thanks! Looks very good to me. Do we want a regrtest of the error message? |
Sorry, something went wrong.
I'm no longer thinking we should, especially now that the static method removes the temptation for there to be a mismatch. |
Sorry, something went wrong.
d716e3b
into
python:main
Dec 10, 2025
|
Thanks @johnslavik for the PR, and @jaraco for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
…ystem functions (pythonGH-142371) * Pick target depending on preconditions * Clarify the news fragment * Add test capturing missed expectation. * Add more idiomatic safe realpath helper * Restore logic where existance and directoriness are checked on realpath. * Link GH issue to test. * Extract a function to check the target. Remove the _safe_realpath, now no longer needed. * Extract method for replacing sys_path, and isolate realpath usage there. * Revert "Extract method for replacing sys_path, and isolate realpath usage there." This reverts commit 855aac3. * Restore _safe_realpath. --------- (cherry picked from commit d716e3b) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
…ystem functions (pythonGH-142371) * Pick target depending on preconditions * Clarify the news fragment * Add test capturing missed expectation. * Add more idiomatic safe realpath helper * Restore logic where existance and directoriness are checked on realpath. * Link GH issue to test. * Extract a function to check the target. Remove the _safe_realpath, now no longer needed. * Extract method for replacing sys_path, and isolate realpath usage there. * Revert "Extract method for replacing sys_path, and isolate realpath usage there." This reverts commit 855aac3. * Restore _safe_realpath. --------- (cherry picked from commit d716e3b) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
|
Hi, I am seeing the following test failure on Solaris with this change present: I am no expert here, but I tried looking into this and apparently opening anything other than regular file or directory from It is however possible to open the pipe descriptor via --- ./cpython-main/Lib/test/test_pdb.py
+++ ./cpython-main/Lib/test/test_pdb.py
@@ -3564,8 +3564,9 @@
def _fd_dir_for_pipe_targets(self):
"""Return a directory exposing live file descriptors, if any."""
proc_fd = "/proc/self/fd"
- if os.path.isdir(proc_fd) and os.path.exists(os.path.join(proc_fd, '0')):
- return proc_fd
+ if not sys.platform.startswith("sunos"):
+ if os.path.isdir(proc_fd) and os.path.exists(os.path.join(proc_fd, '0')):
+ return proc_fd
dev_fd = "/dev/fd"
if os.path.isdir(dev_fd) and os.path.exists(os.path.join(dev_fd, '0')): |
Sorry, something went wrong.
…system functions (GH-142371) (#142497) gh-142315: Don't pass the "real path" of Pdb script target to system functions (GH-142371) * Pick target depending on preconditions * Clarify the news fragment * Add test capturing missed expectation. * Add more idiomatic safe realpath helper * Restore logic where existance and directoriness are checked on realpath. * Link GH issue to test. * Extract a function to check the target. Remove the _safe_realpath, now no longer needed. * Extract method for replacing sys_path, and isolate realpath usage there. * Revert "Extract method for replacing sys_path, and isolate realpath usage there." This reverts commit 855aac3. * Restore _safe_realpath. --------- (cherry picked from commit d716e3b) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
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