Role cache not populated properly for roles created during the lifetime of the client. #17

Closed
opened 2026-02-15 23:16:14 -05:00 by yindo · 1 comment
Owner

Originally created by @LeoCx1000 on GitHub (Mar 26, 2023).

Describe the bug

When creating a role whilst the client is running, the internal cache does not populate.

To Reproduce

# MRC
import revolt, asyncio, aiohttp, logging

async def main():
    async with aiohttp.ClientSession() as session:
        client = revolt.Client(session, TOKEN)
        logging.basicConfig()
        await client.start()


asyncio.run(main())
  1. Run the script.
  2. Create a role.
  3. Add the role to a user.
  4. Delete the role.

Expected behaviour

Role cache gets populated correctly with the newly created role.

Actual behaviour

The role does not seem to be in the cache. Actions involving this role will raise a KeyError:

When adding this newly-created role to the user

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-13' coro=<WebsocketHandler.handle_event() done, defined at <...>\site-packages\revolt\websocket.py:89> exception=KeyError('01GWEX938P16Z2JM5MGYGXN841')>
Traceback (most recent call last):
  File "<...>\site-packages\revolt\websocket.py", line 101, in handle_event
    await func(payload)
  File "<...>\site-packages\revolt\websocket.py", line 289, in handle_servermemberupdate
    member._update(**payload["data"])
  File "<...>\site-packages\revolt\member.py", line 85, in _update
    member_roles = [self.server.get_role(role_id) for role_id in roles]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<...>\site-packages\revolt\member.py", line 85, in <listcomp>
    member_roles = [self.server.get_role(role_id) for role_id in roles]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<...>\site-packages\revolt\server.py", line 192, in get_role
    return self._roles[role_id]
           ~~~~~~~~~~~^^^^^^^^^
KeyError: '01GWEX938P16Z2JM5MGYGXN841'

When deleting the role

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-15' coro=<WebsocketHandler.handle_event() done, defined at <...>\site-packages\revolt\websocket.py:89> exception=KeyError('01GWEX938P16Z2JM5MGYGXN841')>
Traceback (most recent call last):
  File "<...>\site-packages\revolt\websocket.py", line 101, in handle_event
    await func(payload)
  File "<...>\site-packages\revolt\websocket.py", line 331, in handle_serverroledelete
    role = server._roles.pop(payload["role_id"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '01GWEX938P16Z2JM5MGYGXN841'

Library version

0.1.10

Can also be reproduced when installing directly from the repository.

Originally created by @LeoCx1000 on GitHub (Mar 26, 2023). ## **Describe the bug** When creating a role whilst the client is running, the internal cache does not populate. ## **To Reproduce** ```py # MRC import revolt, asyncio, aiohttp, logging async def main(): async with aiohttp.ClientSession() as session: client = revolt.Client(session, TOKEN) logging.basicConfig() await client.start() asyncio.run(main()) ``` 1. Run the script. 2. Create a role. 3. Add the role to a user. 4. Delete the role. ## **Expected behaviour** Role cache gets populated correctly with the newly created role. ## **Actual behaviour** The role does not seem to be in the cache. Actions involving this role will raise a KeyError: #### When adding this newly-created role to the user ```py ERROR:asyncio:Task exception was never retrieved future: <Task finished name='Task-13' coro=<WebsocketHandler.handle_event() done, defined at <...>\site-packages\revolt\websocket.py:89> exception=KeyError('01GWEX938P16Z2JM5MGYGXN841')> Traceback (most recent call last): File "<...>\site-packages\revolt\websocket.py", line 101, in handle_event await func(payload) File "<...>\site-packages\revolt\websocket.py", line 289, in handle_servermemberupdate member._update(**payload["data"]) File "<...>\site-packages\revolt\member.py", line 85, in _update member_roles = [self.server.get_role(role_id) for role_id in roles] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<...>\site-packages\revolt\member.py", line 85, in <listcomp> member_roles = [self.server.get_role(role_id) for role_id in roles] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<...>\site-packages\revolt\server.py", line 192, in get_role return self._roles[role_id] ~~~~~~~~~~~^^^^^^^^^ KeyError: '01GWEX938P16Z2JM5MGYGXN841' ``` #### When deleting the role ```py ERROR:asyncio:Task exception was never retrieved future: <Task finished name='Task-15' coro=<WebsocketHandler.handle_event() done, defined at <...>\site-packages\revolt\websocket.py:89> exception=KeyError('01GWEX938P16Z2JM5MGYGXN841')> Traceback (most recent call last): File "<...>\site-packages\revolt\websocket.py", line 101, in handle_event await func(payload) File "<...>\site-packages\revolt\websocket.py", line 331, in handle_serverroledelete role = server._roles.pop(payload["role_id"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: '01GWEX938P16Z2JM5MGYGXN841' ``` ## **Library version** `0.1.10` Can also be reproduced when installing directly from the repository.
yindo added the bug label 2026-02-15 23:16:14 -05:00
yindo closed this issue 2026-02-15 23:16:14 -05:00
Author
Owner

@Zomatree commented on GitHub (Mar 26, 2023):

Fixed in https://github.com/revoltchat/revolt.py/commit/e99b6edee3980875009266b89774f303b287cf11.

@Zomatree commented on GitHub (Mar 26, 2023): Fixed in https://github.com/revoltchat/revolt.py/commit/e99b6edee3980875009266b89774f303b287cf11.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stoatchat/python-client-sdk#17