canonical / canonical/python-libmaas

Bug on async Events methods

Aperta
#311 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
stale
Lingua principale
Python
Stelle
65
Fork
71
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in maas/client/viscera/events.py, nei metodi asincroni prev e next indicati alle righe 169 e 180, quindi riproduci il problema con l’esempio fornito di iterazione asincrona events.forwards(). Il lavoro è completato quando l’iterazione tra le pagine degli eventi non produce più un oggetto coroutine né il TypeError riportato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
1/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.