# Buggy code
def warm_users(self, users: List[User]) -> None:
    for user in users:
        user_id = user.user_id
        cached_displayname = self.userid_to_displayname.get(user_id)

        if cached_displayname is None:
            # The cache is cold, query and warm it.
            if not user.displayname:
                # Handles an edge case where the Matrix federation does not
                # have the profile for a given userid. The server response
                # is roughly:
                #
                #   {"errcode":"M_NOT_FOUND","error":"Profile was not found"} or
                #   {"errcode":"M_UNKNOWN","error":"Failed to fetch profile"}
                try:
                    user.get_display_name()
                except MatrixRequestError as ex:
                    # We ignore the error here and set user presence: SERVER_ERROR at the
                    # calling site
                    log.error(
                        f"Ignoring failed `get_display_name` for user {user}",
                        exc_info=ex,
                    )

            if user.displayname is not None:
                self.userid_to_displayname[user.user_id] = user.displayname

        elif user.displayname is None:
            user.displayname = cached_displayname

        elif user.displayname != cached_displayname:
            log.debug(
                "User displayname changed!",
                cached=cached_displayname,
                current=user.displayname,
            )
            self.userid_to_displayname[user.user_id] = user.displayname


# Traceback (matrix_client.errors.MatrixRequestError)
Traceback (most recent call last):
File "raiden/ui/cli.py", line 617, in run
File "raiden/ui/runners.py", line 21, in run_services
File "raiden/ui/app.py", line 446, in run_app
File "raiden/app.py", line 90, in start
File "raiden/raiden_service.py", line 444, in start
File "raiden/raiden_service.py", line 552, in _start_transport
File "raiden/network/transport/matrix/transport.py", line 449, in start
File "raiden/network/transport/matrix/utils.py", line 711, in login
File "raiden/network/transport/matrix/utils.py", line 623, in first_login
File "matrix_client/client.py", line 270, in login
File "matrix_client/api.py", line 160, in login
File "raiden/network/transport/matrix/client.py", line 180, in _send
File "matrix_client/api.py", line 691, in _send
matrix_client.errors.MatrixRequestError: 500: {"errcode":"M_UNKNOWN","error":"Internal server error"}
``

# Fixed code
def warm_users(self, users: List[User]) -> None:
    for user in users:
        user_id = user.user_id
        cached_displayname = self.userid_to_displayname.get(user_id)

        if cached_displayname is None:
            # The cache is cold, query and warm it.
            if not user.displayname:
                # Handles an edge case where the Matrix federation does not
                # have the profile for a given userid. The server response
                # is roughly:
                #
                #   {"errcode":"M_NOT_FOUND","error":"Profile was not found"} or
                #   {"errcode":"M_UNKNOWN","error":"Failed to fetch profile"}
                try:
                    user.get_display_name()
                except MatrixRequestError as ex:
                    # We ignore the error here and set user presence: SERVER_ERROR at the
                    # calling site
                    log.error(
                        "Ignoring Matrix error in `get_display_name`",
                        exc_info=ex,
                        user_id=user.user_id,
                    )

            if user.displayname is not None:
                self.userid_to_displayname[user.user_id] = user.displayname

        elif user.displayname is None:
            user.displayname = cached_displayname

        elif user.displayname != cached_displayname:
            log.debug(
                "User displayname changed!",
                cached=cached_displayname,
                current=user.displayname,
            )
            self.userid_to_displayname[user.user_id] = user.displayname