canonical / canonical/python-libmaas

Bug on async Events methods

オープン
#311 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
stale
主要言語
Python
スター
65
フォーク
71
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

maas/client/viscera/events.py の、169 行目と 180 行目で参照されている非同期の prev メソッドと next メソッドから始め、提供されている events.forwards() の非同期イテレーション例で問題を再現してください。イベントページをまたいでイテレーションしても、coroutine オブジェクトや報告されている TypeError が生成されなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api
issue の種類
バグ
難易度
1/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
50/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。