# Buggy code
def _sync_data_from_server_and_replace_local(self) -> bool:
    """
    Performs syncing of data from server and replaces local db

    Returns true for success and False for error/failure

    May raise:
    - PremiumAuthenticationError due to an UnableToDecryptRemoteData
    coming from  decompress_and_decrypt_db. This happens when the given password
    does not match the one on the saved DB.
    """
    assert self.premium, "This function has to be called with a not None premium"
    try:
        result = self.premium.pull_data()
    except RemoteError as e:
        log.debug("sync from server -- pulling failed.", error=str(e))
        return False

    try:
        self.data.decompress_and_decrypt_db(self.password, result["data"])
    except UnableToDecryptRemoteData:
        raise PremiumAuthenticationError(
            "The given password can not unlock the database that was retrieved  from "
            "the server. Make sure to use the same password as when the account was created.",
        )

    return True


# Traceback (AssertionError)
[07/10/2020 10:06:45 CEST] ERROR rotkehlchen.api.server: Exception on /api/1/users [PUT]
Traceback (most recent call last):
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/flask_restful/__init__.py", line 458, in wrapper
resp = resource(*args, **kwargs)
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/flask_restful/__init__.py", line 573, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/webargs/core.py", line 366, in wrapper
return func(*args, **kwargs)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/api/v1/resources.py", line 511, in put
initial_settings=initial_settings,
File "/home/lefteris/w/rotkehlchen/rotkehlchen/api/rest.py", line 812, in create_new_user
initial_settings=initial_settings,
File "/home/lefteris/w/rotkehlchen/rotkehlchen/rotkehlchen.py", line 194, in unlock_user
sync_approval=sync_approval,
File "/home/lefteris/w/rotkehlchen/rotkehlchen/premium/sync.py", line 267, in try_premium_at_start
if self._sync_data_from_server_and_replace_local():
File "/home/lefteris/w/rotkehlchen/rotkehlchen/premium/sync.py", line 128, in _sync_data_from_server_and_replace_local
self.data.decompress_and_decrypt_db(self.password, result['data'])
File "/home/lefteris/w/rotkehlchen/rotkehlchen/data_handler.py", line 229, in decompress_and_decrypt_db
decrypted_data = decrypt(password.encode(), encrypted_data)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/crypto.py", line 34, in decrypt
assert isinstance(given_source, str), 'source should be given in string'
AssertionError: source should be given in string
[07/10/2020 10:06:45 CEST] INFO rotkehlchen.api.server.pywsgi: 127.0.0.1 - - "PUT /api/1/users HTTP/1.1" 500 216 0.627664

# Fixed code
def _sync_data_from_server_and_replace_local(self) -> bool:
    """
    Performs syncing of data from server and replaces local db

    Returns true for success and False for error/failure

    May raise:
    - PremiumAuthenticationError due to an UnableToDecryptRemoteData
    coming from  decompress_and_decrypt_db. This happens when the given password
    does not match the one on the saved DB.
    """
    assert self.premium, "This function has to be called with a not None premium"
    try:
        result = self.premium.pull_data()
    except RemoteError as e:
        log.debug("sync from server -- pulling failed.", error=str(e))
        return False

    if result["data"] is None:
        log.debug("sync from server -- no data found.")
        return False

    try:
        self.data.decompress_and_decrypt_db(self.password, result["data"])
    except UnableToDecryptRemoteData:
        raise PremiumAuthenticationError(
            "The given password can not unlock the database that was retrieved  from "
            "the server. Make sure to use the same password as when the account was created.",
        )

    return True