Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix warning about coroutine method 'aclose' of 'AsyncSession.resolve_redirects' was never awaited #181

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Release History
===============

3.11.0 (2024-11-20)
-------------------

**Added**
- base_url parameter to `niquests.Session` or `niquests.AsyncSession`. automatically prefix every request emitted with it. (#179)

**Fixed**
- warning about coroutine method 'aclose' of 'AsyncSession.resolve_redirects' was never awaited.

3.10.3 (2024-11-13)
------------------

Expand Down
14 changes: 8 additions & 6 deletions src/niquests/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,13 @@ async def on_early_response(early_response: Response) -> None:
if r.lazy is True:

async def _redirect_method_ref(x, y):
aiter_gen = self.resolve_redirects(x, y, yield_requests=True, **kwargs)
try:
return await self.resolve_redirects(
x, y, yield_requests=True, **kwargs
).__anext__()
return await aiter_gen.__anext__()
except StopAsyncIteration:
return None
finally:
await aiter_gen.aclose()

r._resolve_redirect = _redirect_method_ref

Expand Down Expand Up @@ -567,13 +568,14 @@ async def _redirect_method_ref(x, y):
# If redirects aren't being followed, store the response on the Request for Response.next().
if not allow_redirects:
if r.is_redirect:
gen = self.resolve_redirects(r, request, yield_requests=True, **kwargs)

try:
gen = self.resolve_redirects(
r, request, yield_requests=True, **kwargs
)
r._next = await gen.__anext__() # type: ignore[assignment]
except StopAsyncIteration:
pass
finally:
await gen.aclose()

if not stream:
if isinstance(r, AsyncResponse):
Expand Down
Loading