# Buggy code
def get_keyring(cls):
    """
    Attempts to get secure keyring at runtime if current keyring is insecure.
    Once it finds a secure keyring, it wil always use that keyring
    """
    if cls._keyring is None or not cls._keyring.is_primary:
        if sys.platform == "darwin":  # Use Keychain on macOS
            from .darwin import VortaDarwinKeyring

            cls._keyring = VortaDarwinKeyring()
        else:  # Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
            import secretstorage
            from .secretstorage import VortaSecretStorageKeyring

            # secretstorage has two different libraries based on version
            if parse_version(secretstorage.__version__) >= parse_version("3.0.0"):
                from jeepney.wrappers import DBusErrorResponse as DBusException
            else:
                from dbus.exceptions import DBusException

            try:
                cls._keyring = VortaSecretStorageKeyring()
            except (
                secretstorage.exceptions.SecretStorageException,
                DBusException,
            ):  # Try to use KWallet (KDE)
                from .kwallet import VortaKWallet5Keyring, KWalletNotAvailableException

                try:
                    cls._keyring = VortaKWallet5Keyring()
                except (
                    KWalletNotAvailableException
                ):  # Save passwords in DB, if all else fails.
                    from .db import VortaDBKeyring

                    cls._keyring = VortaDBKeyring()
    return cls._keyring


# Traceback (dbus.exceptions.DBusException)
2020-08-31 20:53:34,066 - vorta.borg.borg_thread - DEBUG - Using VortaSecretStorageKeyring keyring to store passwords.
2020-08-31 20:53:34,066 - asyncio - DEBUG - Using selector: EpollSelector
Traceback (most recent call last):
File "/home/user/.local/lib/python3.8/site-packages/vorta/views/repo_add_dialog.py", line 64, in run
params = BorgInitThread.prepare(self.values)
File "/home/user/.local/lib/python3.8/site-packages/vorta/borg/init.py", line 20, in prepare
ret = super().prepare(profile)
File "/home/user/.local/lib/python3.8/site-packages/vorta/borg/borg_thread.py", line 121, in prepare
ret['password'] = keyring.get_password('vorta-repo', profile.repo.url)
File "/home/user/.local/lib/python3.8/site-packages/vorta/keyring/secretstorage.py", line 30, in get_password
collection = secretstorage.get_default_collection(self.connection)
File "/usr/lib/python3/dist-packages/secretstorage/collection.py", line 155, in get_default_collection
return Collection(bus)
File "/usr/lib/python3/dist-packages/secretstorage/collection.py", line 42, in __init__
self.collection_props_iface.Get(COLLECTION_IFACE, 'Label',
File "/usr/lib/python3/dist-packages/secretstorage/util.py", line 31, in function_out
return function_in(*args, **kwargs)
File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in __call__
return self._connection.call_blocking(self._named_service,
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/freedesktop/secrets/aliases/default'

# Fixed code
def get_keyring(cls):
    """
    Attempts to get secure keyring at runtime if current keyring is insecure.
    Once it finds a secure keyring, it wil always use that keyring
    """
    if cls._keyring is None or not cls._keyring.is_primary:
        if sys.platform == "darwin":  # Use Keychain on macOS
            from .darwin import VortaDarwinKeyring

            cls._keyring = VortaDarwinKeyring()
        else:
            # Try to use KWallet (KDE)
            from .kwallet import VortaKWallet5Keyring, KWalletNotAvailableException

            try:
                cls._keyring = VortaKWallet5Keyring()
            except KWalletNotAvailableException:
                # Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
                # Put this last as gnome keyring is included by default on many distros
                import secretstorage
                from .secretstorage import VortaSecretStorageKeyring

                # secretstorage has two different libraries based on version
                if parse_version(secretstorage.__version__) >= parse_version("3.0.0"):
                    from jeepney.wrappers import DBusErrorResponse as DBusException
                else:
                    from dbus.exceptions import DBusException

                try:
                    cls._keyring = VortaSecretStorageKeyring()
                except (secretstorage.exceptions.SecretStorageException, DBusException):
                    # Save passwords in DB, if all else fails.
                    from .db import VortaDBKeyring

                    cls._keyring = VortaDBKeyring()
    return cls._keyring