canonical / canonical/python-libmaas
Bug on async Events methods
- Lenguaje dominante
- Python
- Estrellas
- 65
- Forks
- 71
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
The `async def prev(self, count=None)` and `async def next(self, count=None)` methods on [client/viscera/events.py](https://github.com/canonical/python-libmaas/blob/0.6.8/maas/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:
```python
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
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:
- https://github.com/canonical/python-libmaas/blob/0.6.8/maas/client/viscera/events.py#L169
- https://github.com/canonical/python-libmaas/blob/0.6.8/maas/client/viscera/events.py#L180
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en maas/client/viscera/events.py, en los métodos asíncronos prev y next mencionados en las líneas 169 y 180, y luego reproduce el problema con el ejemplo proporcionado de iteración asíncrona events.forwards(). Se considera terminado cuando iterar por las páginas de eventos ya no produce un objeto coroutine ni el TypeError indicado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 1/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 50/100