andreahlert commented on PR #681:
URL: https://github.com/apache/burr/pull/681#issuecomment-4117890120
> Good solution to #546! The `_AsyncPersisterContextManager` approach is
clean — supporting both `await` and `async with` from the same factory method
is a nice UX improvement.
>
> Two items to address:
>
> 1. **Move `_AsyncPersisterContextManager` to `burr/common/`**. Having
`b_asyncpg.py` import from `b_aiosqlite.py` is an unwanted cross-dependency
between unrelated integrations. Something like `burr/common/types.py` or a new
`burr/common/async_utils.py` would be a better home.
> 2. **Add tests for the `async with` pattern.** All existing tests use
`await`, so the new context manager functionality is untested. At minimum, a
test like:
> ```python
> async def test_async_sqlite_from_values_as_context_manager(tmp_path):
> db_path = str(tmp_path / "test.db")
> async with AsyncSQLitePersister.from_values(db_path=db_path) as
persister:
> await persister.initialize()
> await persister.save("pk", "app1", 1, "pos", State({"k": "v"}),
"completed")
> loaded = await persister.load("pk", "app1")
> assert loaded is not None
> ```
>
> Also checked: `AsyncRedisBasePersister.from_values` is already a regular
(non-async) method, so it doesn't have this issue. The fix correctly covers the
only two affected persisters.
Addressed all three points. While testing the fix in an isolated Docker
container (Python 3.11), I caught two additional bugs:
- __aexit__ would crash with AttributeError if __aenter__ failed (e.g. bad
db path), because self._persister was still None. Now guarded.
- The wrapper could be silently consumed twice (coroutine exhaustion). Added
a _consumed flag that raises RuntimeError with a clear message.
Also fixed the parallelism.rst docs that were missing await on from_values()
calls, and removed the now-redundant AsyncSQLiteContextManager helper from both
test files.
LGTM. Could you please take an extra look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]