Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-76912: Raise OSError from any failure in getpass.getuser() #29739

Merged
merged 11 commits into from
Nov 27, 2023

Conversation

jacobtylerwalls
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls commented Nov 24, 2021

bpo-32731

Before
If the initial lookup against environment variables fails, ImportError was raised on Windows, and, on other systems, if the secondary lookup against the password database fails, KeyError was raised. Documentation only said an "Exception" is raised.

Now
Errors are re-raised as OSError and documented.

https://bugs.python.org/issue32731

Fixes #76912

Previously, if the username was not set in certain environment variables, ImportError escaped on Windows systems, and it was possible for KeyError to escape on other systems if getpwuid() failed.
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 25, 2021
Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

Looks ok and tests pass.

@jacobtylerwalls jacobtylerwalls changed the title bpo-32731: Raise OSError from any failure in getpass.getuser() gh-76912: Raise OSError from any failure in getpass.getuser() Jun 7, 2022
@arhadthedev
Copy link
Member

@gpshead as an author of the parent issue.

Doc/library/getpass.rst Show resolved Hide resolved
Lib/getpass.py Show resolved Hide resolved
@gpshead gpshead self-assigned this Nov 19, 2023
@gpshead gpshead added the 3.13 bugs and security fixes label Nov 19, 2023
@gpshead gpshead merged commit 99a73c3 into python:main Nov 27, 2023
29 checks passed
@jacobtylerwalls jacobtylerwalls deleted the getpass branch November 27, 2023 18:41
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…ython#29739)

* bpo-32731: Raise OSError from any failure in getpass.getuser()
Previously, if the username was not set in certain environment variables, ImportError escaped on Windows systems, and it was possible for KeyError to escape on other systems if getpwuid() failed.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…ython#29739)

* bpo-32731: Raise OSError from any failure in getpass.getuser()
Previously, if the username was not set in certain environment variables, ImportError escaped on Windows systems, and it was possible for KeyError to escape on other systems if getpwuid() failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getpass.getuser() raises an unspecified exceptions (ImportError, OSError, etc)
7 participants