diff --git a/news/12751.bugfix.rst b/news/12751.bugfix.rst new file mode 100644 index 00000000000..70c6680a8a9 --- /dev/null +++ b/news/12751.bugfix.rst @@ -0,0 +1 @@ +Avoid keyring logging crashes when pip is run in verbose mode. diff --git a/src/pip/_internal/network/auth.py b/src/pip/_internal/network/auth.py index 4705b55a7aa..1a2606ed080 100644 --- a/src/pip/_internal/network/auth.py +++ b/src/pip/_internal/network/auth.py @@ -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), diff --git a/src/pip/_internal/utils/logging.py b/src/pip/_internal/utils/logging.py index 90df257821e..41f6eb51a26 100644 --- a/src/pip/_internal/utils/logging.py +++ b/src/pip/_internal/utils/logging.py @@ -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)