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

Backport PR #23598 on branch 6.x (PR: Catch error when there's no keyring backend available (Config)) #23600

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion spyder/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import logging
import os
import os.path as osp
import sys
import traceback
from typing import Any, Dict, List, Optional, Set, Tuple
import weakref

# Third-party imports
import keyring
from keyring.errors import NoKeyringError

# Local imports
from spyder.api.utils import PrefixedTuple
Expand Down Expand Up @@ -574,7 +576,33 @@ def set(self, section, option, value, verbose=False, save=True,
f"Saving option {option} with keyring because it was marked "
f"as secure."
)
keyring.set_password(section, option, value)

# Catch error when there's no keyring backend available.
# Fixes spyder-ide/spyder#22623
try:
keyring.set_password(section, option, value)
except NoKeyringError:
# This file must not have top-level Qt imports. This also
# prevents possible circular imports.
from qtpy.QtWidgets import QMessageBox
from spyder_kernels.utils.pythonenv import is_conda_env

pkg_manager = "conda" if is_conda_env(sys.prefix) else "pip"
msg = _(
"It was not possible to save a configuration setting "
"securely. A possible solution is to install the "
"<tt>keyrings.alt</tt> package with {}.<br><br>"
"<bb>Note</bb>: That package may have security risks or "
"other implications. Hence, it's not advised to use it in "
"general production or security-sensitive systems."
).format(pkg_manager)

QMessageBox.critical(
None,
_("Error"),
msg,
QMessageBox.Ok,
)
else:
config.set(
section=section,
Expand Down
Loading