# Buggy code
async def copy_room_tags_and_direct_to_room(
    self, old_room_id, new_room_id, user_id
) -> None:
    """Copies the tags and direct room state from one room to another.

    Args:
        old_room_id: The room ID of the old room.
        new_room_id: The room ID of the new room.
        user_id: The user's ID.
    """
    # Retrieve user account data for predecessor room
    user_account_data, _ = await self.store.get_account_data_for_user(user_id)

    # Copy direct message state if applicable
    direct_rooms = user_account_data.get("m.direct", {})

    # Check which key this room is under
    if isinstance(direct_rooms, dict):
        for key, room_id_list in direct_rooms.items():
            if old_room_id in room_id_list and new_room_id not in room_id_list:
                # Add new room_id to this key
                direct_rooms[key].append(new_room_id)

                # Save back to user's m.direct account data
                await self.store.add_account_data_for_user(
                    user_id, "m.direct", direct_rooms
                )
                break

    # Copy room tags if applicable
    room_tags = await self.store.get_tags_for_room(user_id, old_room_id)

    # Copy each room tag to the new room
    for tag, tag_content in room_tags.items():
        await self.store.add_tag_to_room(user_id, new_room_id, tag, tag_content)


# 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 copy_room_tags_and_direct_to_room(
    self, old_room_id, new_room_id, user_id
) -> None:
    """Copies the tags and direct room state from one room to another.

    Args:
        old_room_id: The room ID of the old room.
        new_room_id: The room ID of the new room.
        user_id: The user's ID.
    """
    # Retrieve user account data for predecessor room
    user_account_data, _ = await self.store.get_account_data_for_user(user_id)

    # Copy direct message state if applicable
    direct_rooms = user_account_data.get(AccountDataTypes.DIRECT, {})

    # Check which key this room is under
    if isinstance(direct_rooms, dict):
        for key, room_id_list in direct_rooms.items():
            if old_room_id in room_id_list and new_room_id not in room_id_list:
                # Add new room_id to this key
                direct_rooms[key].append(new_room_id)

                # Save back to user's m.direct account data
                await self.store.add_account_data_for_user(
                    user_id, AccountDataTypes.DIRECT, direct_rooms
                )
                break

    # Copy room tags if applicable
    room_tags = await self.store.get_tags_for_room(user_id, old_room_id)

    # Copy each room tag to the new room
    for tag, tag_content in room_tags.items():
        await self.store.add_tag_to_room(user_id, new_room_id, tag, tag_content)