Skip to content

Commit

Permalink
Merge pull request #12752 from jfly/issue-12751-incorrect-logging-ass…
Browse files Browse the repository at this point in the history
…ertion

Don't assume that `LogRecord.args` is a tuple
  • Loading branch information
pradyunsg authored Jul 13, 2024
2 parents 888d2cc + ac61d71 commit 58aacf0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/12751.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid keyring logging crashes when pip is run in verbose mode.
4 changes: 4 additions & 0 deletions src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ def _get_keyring_auth(
try:
return self.keyring_provider.get_auth_info(url, username)
except Exception as exc:
# Log the full exception (with stacktrace) at debug, so it'll only
# show up when running in verbose mode.
logger.debug("Keyring is skipped due to an exception", exc_info=True)
# Always log a shortened version of the exception.
logger.warning(
"Keyring is skipped due to an exception: %s",
str(exc),
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def emit(self, record: logging.LogRecord) -> None:
style: Optional[Style] = None

# If we are given a diagnostic error to present, present it with indentation.
assert isinstance(record.args, tuple)
if getattr(record, "rich", False):
assert isinstance(record.args, tuple)
(rich_renderable,) = record.args
assert isinstance(
rich_renderable, (ConsoleRenderable, RichCast, str)
Expand Down

0 comments on commit 58aacf0

Please sign in to comment.