Skip to content

Bug on async Events methods #311

Description

@leomarssilva

The async def prev(self, count=None) and async def next(self, count=None) methods on client/viscera/events.py are not using await when calling self._fetch, which is causing errors when the async iterator tries to continue reading events of a previous/next page.

How to reproduce:

events = await client.events.query()

async for e in events.forwards():
    print(e.event_id, e.event_type)

The snippet above will fetch some events and then throw an error:

...
1902 Performing PXE boot
1906 Loading ephemeral
1907 Image Deployed
1909 Deployed

Traceback (most recent call last):
  File "/maas_tests/env/lib/python3.13/site-packages/maas/client/viscera/events.py", line 259, in __anext__
    return next(self._current_iter)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/maas_tests/env/lib/python3.13/site-packages/marimo/_runtime/executor.py", line 115, in execute_cell_async
    await eval(cell.body, glbls)
  Cell marimo://test-python-libmaas.py#cell=cell-17, line 3, in <module>
    async for e in events.forwards():
        print(e.event_id, e.event_type)
  File "/maas_tests/env/lib/python3.13/site-packages/maas/client/viscera/events.py", line 262, in __anext__
    self._current_iter = reversed(self._current)
                         ~~~~~~~~^^^^^^^^^^^^^^^
TypeError: 'coroutine' object is not reversible

To fix, we just need to add await to the following lines:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions