-
Notifications
You must be signed in to change notification settings - Fork 62
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
Unexpected behavior of async response_handler
callback
#256
Comments
Hey, @returnnullptr - thanks for reporting! I think you caught something deeper. #258 should fix this. |
Async callbacks are being wrapped by ThreadedCoroutine when they shouldn't be. For some context, the purpose of ThreadedCoroutine is to allow sync callbacks with aiohttp client. When the callback is an async function, this condition should skip this behavior. See #256
This also seems to have broken my app. I find that objects I await return a co-routine object and have to be awaited again.... |
Hey, @HarvsG - Got it. The fix will be part of v0.9.7, which I'll be releasing this week. ETA is by March 11th |
Great, my app actually targets uplink 0.9.4 but is is used within Homeassisstant which seems to be forcing it to use a newer version with the bug. Edit: In the meantime I have fixed the issue by ssh-ing into my machine, then running |
v0.9.7 is live now and includes the fix for this issue |
hmm, still getting the same error with 0.9.7 |
@HarvsG - Interesting.. I might have missed something, or you might be running into a similar issue with a different cause. Could you check out this test case and let me know if it captures your usage? (i.e., invoking a method wrapped by response handler with an async http client) |
This might be a different issue altogether, in which case I can file a separate ticket, but we've found a similar issue with the usage of the aiohttp client and uplink >= 0.9.6. In our system, we enqueue many (tens of thousands) requests, and execute them with a concurrency of, say, 100. For example:
In short, we've noticed that when using an aiohttp client in conjunction with the We've added logging and found that these retried requests don't spend that time waiting for a connection or anything; once the When using the aiohttp client with uplink 0.9.5, the retry logic works as expected and is fully performant even in the case of occasional retries due to server/network errors. I'm not sure if this is any relation to the response_handler callback issue mentioned here, but the timing and relation to aiohttp made us think this could be related. |
Using converters with request handlers seems to be another problem. I used the simple test case and rewritten something like this to reproduce the issue: import asyncio
import pydantic
import uplink
import uplink.converters.pydantic_ # noqa
from uplink.clients.aiohttp_ import AiohttpClient
class MyModel(pydantic.BaseModel):
something: str
@uplink.response_handler
async def simple_async_handler(response):
return {"something": "somestr"}
class Calendar(uplink.Consumer):
@simple_async_handler
@uplink.get("todos/{todo_id}")
def get_todo(self, todo_id) -> MyModel:
pass
async def main():
calendar = Calendar(base_url="https://example.com/", client=AiohttpClient())
# Run
response = await calendar.get_todo(todo_id=1)
asyncio.run(main()) Running this results in:
I tracked it down to here: Line 102 of uplink.hooks.TransactionHookChain.handle_response def handle_response(self, consumer, response):
for hook in self._response_handlers:
response = hook.handle_response(consumer, response)
return response
Maybe this can be fixed by introducing an async version of the |
Describe the bug
Changes made in #248 break the async
response_handler
callback behavior.To Reproduce
Define asynchronous response handler:
Define consumer method decorated this way:
Call the method:
Since the
0.9.6
, awaited method call is a coroutine.Expected behavior
A consumer method decorated this way returns a result using a single
await
.Additional context
The
aiohttp
client is used.The text was updated successfully, but these errors were encountered: