# Buggy code
async def _get_all_rooms(
    self, sync_result_builder: "SyncResultBuilder", ignored_users: Set[str]
) -> _RoomChanges:
    """Returns entries for all rooms for the user.

    Args:
        sync_result_builder
        ignored_users: Set of users ignored by user.

    """

    user_id = sync_result_builder.sync_config.user.to_string()
    since_token = sync_result_builder.since_token
    now_token = sync_result_builder.now_token
    sync_config = sync_result_builder.sync_config

    membership_list = (
        Membership.INVITE,
        Membership.JOIN,
        Membership.LEAVE,
        Membership.BAN,
    )

    room_list = await self.store.get_rooms_for_local_user_where_membership_is(
        user_id=user_id, membership_list=membership_list
    )

    room_entries = []
    invited = []

    for event in room_list:
        if event.membership == Membership.JOIN:
            room_entries.append(
                RoomSyncResultBuilder(
                    room_id=event.room_id,
                    rtype="joined",
                    events=None,
                    newly_joined=False,
                    full_state=True,
                    since_token=since_token,
                    upto_token=now_token,
                )
            )
        elif event.membership == Membership.INVITE:
            if event.sender in ignored_users:
                continue
            invite = await self.store.get_event(event.event_id)
            invited.append(InvitedSyncResult(room_id=event.room_id, invite=invite))
        elif event.membership in (Membership.LEAVE, Membership.BAN):
            # Always send down rooms we were banned or kicked from.
            if not sync_config.filter_collection.include_leave:
                if event.membership == Membership.LEAVE:
                    if user_id == event.sender:
                        continue

            leave_token = now_token.copy_and_replace(
                "room_key", RoomStreamToken(None, event.stream_ordering)
            )
            room_entries.append(
                RoomSyncResultBuilder(
                    room_id=event.room_id,
                    rtype="archived",
                    events=None,
                    newly_joined=False,
                    full_state=True,
                    since_token=since_token,
                    upto_token=leave_token,
                )
            )

    return _RoomChanges(room_entries, invited, [], [])


# Traceback (AttributeError)
2020-09-20 07:53:32,780 - synapse.http.server - 80 - ERROR - GET-8896 - Failed handle request via 'SyncRestServlet': <XForwardedForRequest at 0xffff882be940 method='GET' uri='/_matrix/client/r0/sync?fil>
Traceback (most recent call last):
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/http/server.py", line 229, in _async_render_wrapper
callback_return = await self._async_render(request)
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/http/server.py", line 406, in _async_render
callback_return = await raw_callback_return
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/rest/client/v2_alpha/sync.py", line 174, in on_GET
sync_result = await self.sync_handler.wait_for_sync_for_user(
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/handlers/sync.py", line 278, in wait_for_sync_for_user
res = await self.response_cache.wrap(
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/handlers/sync.py", line 310, in _wait_for_sync_for_user
result = await self.current_sync_for_user(
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/handlers/sync.py", line 342, in current_sync_for_user
return await self.generate_sync_result(sync_config, since_token, full_state)
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/handlers/sync.py", line 998, in generate_sync_result
res = await self._generate_sync_entry_for_rooms(
File "/home/ubuntu/synapse/env/lib/python3.8/site-packages/synapse/handlers/sync.py", line 1395, in _generate_sync_entry_for_rooms
ignored_users = ignored_account_data.get("ignored_users", {}).keys()
AttributeError: 'list' object has no attribute 'keys'

# Fixed code
async def _get_all_rooms(
    self, sync_result_builder: "SyncResultBuilder", ignored_users: FrozenSet[str]
) -> _RoomChanges:
    """Returns entries for all rooms for the user.

    Args:
        sync_result_builder
        ignored_users: Set of users ignored by user.

    """

    user_id = sync_result_builder.sync_config.user.to_string()
    since_token = sync_result_builder.since_token
    now_token = sync_result_builder.now_token
    sync_config = sync_result_builder.sync_config

    membership_list = (
        Membership.INVITE,
        Membership.JOIN,
        Membership.LEAVE,
        Membership.BAN,
    )

    room_list = await self.store.get_rooms_for_local_user_where_membership_is(
        user_id=user_id, membership_list=membership_list
    )

    room_entries = []
    invited = []

    for event in room_list:
        if event.membership == Membership.JOIN:
            room_entries.append(
                RoomSyncResultBuilder(
                    room_id=event.room_id,
                    rtype="joined",
                    events=None,
                    newly_joined=False,
                    full_state=True,
                    since_token=since_token,
                    upto_token=now_token,
                )
            )
        elif event.membership == Membership.INVITE:
            if event.sender in ignored_users:
                continue
            invite = await self.store.get_event(event.event_id)
            invited.append(InvitedSyncResult(room_id=event.room_id, invite=invite))
        elif event.membership in (Membership.LEAVE, Membership.BAN):
            # Always send down rooms we were banned or kicked from.
            if not sync_config.filter_collection.include_leave:
                if event.membership == Membership.LEAVE:
                    if user_id == event.sender:
                        continue

            leave_token = now_token.copy_and_replace(
                "room_key", RoomStreamToken(None, event.stream_ordering)
            )
            room_entries.append(
                RoomSyncResultBuilder(
                    room_id=event.room_id,
                    rtype="archived",
                    events=None,
                    newly_joined=False,
                    full_state=True,
                    since_token=since_token,
                    upto_token=leave_token,
                )
            )

    return _RoomChanges(room_entries, invited, [], [])