Handle storing None values in keyring

Write an empty string as value to the keyring if None is parsed and
return a None value if an empty string was parsed from the keyring.

CURA-7180_keyring_none_value
This commit is contained in:
jelle Spijker 2021-04-04 12:27:43 +02:00 committed by Jelle Spijker
parent 279edf7a37
commit 23ba1745a4
No known key found for this signature in database
GPG Key ID: 6662DC033BE6B99A

View File

@ -29,7 +29,8 @@ class KeyringAttribute:
def __get__(self, instance: Type["BaseModel"], owner: type) -> str:
if self._store_secure:
try:
return keyring.get_password("cura", self._keyring_name)
value = keyring.get_password("cura", self._keyring_name)
return value if value != "" else None
except NoKeyringError:
self._store_secure = False
Logger.logException("w", "No keyring backend present")
@ -41,7 +42,7 @@ class KeyringAttribute:
if self._store_secure:
setattr(instance, self._name, None)
try:
keyring.set_password("cura", self._keyring_name, value)
keyring.set_password("cura", self._keyring_name, value if value is not None else "")
except PasswordSetError:
self._store_secure = False
if self._name not in DONT_EVER_STORE_LOCALLY: