-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[FIX] Credentials: handling password credentials error #2354
Conversation
Orange/widgets/credentials.py
Outdated
try: | ||
return keyring.get_password(self.service_name, item) | ||
except Exception: | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we default to None as is returned when the key is not yet set?
>>> import keyring
>>> print(keyring.get_password('Orange3 - random test', 'nonexistent key')
None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
@@ -32,7 +32,10 @@ def __setattr__(self, key, value): | |||
keyring.set_password(self.service_name, key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the setter also raise e.g. if the keyring isn't unlocked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does.
Codecov Report
@@ Coverage Diff @@
## master #2354 +/- ##
==========================================
- Coverage 73.37% 73.35% -0.03%
==========================================
Files 317 317
Lines 55570 55615 +45
==========================================
+ Hits 40777 40797 +20
- Misses 14793 14818 +25 |
Orange/widgets/credentials.py
Outdated
except Exception: | ||
log.error("Failed to get password for '{}'.".format(self.service_name), | ||
exc_info=True) | ||
return None | ||
|
||
def __delattr__(self, item): | ||
keyring.delete_password(self.service_name, item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the deleter, then, also raise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure it can. For instance:
# keyring.errors.PasswordDeleteError: No such password!
# RuntimeError:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you catch more specific exceptions? PasswordSetError
and PasswordDeleteError
from https://github.com/jaraco/keyring/blob/master/keyring/errors.py#L3 should do the trick.
Issue
biolab/orange3-text#253
Description of changes
try except block
Includes