Conversation
Bibo-Joshi
left a comment
There was a problem hiding this comment.
Hi. Thanks for taking the time to PR for that :) I hope the authors of python-telegram-bot/python-telegram-bot#4560 appreciate it :)
- read_timeout property needs to be implemented, but this doesn't make sense since aiohttp doesn't have that timeout. Why do even have this property do we actually need it? Should I just pass the most fitting timeout like I do?
This was introduced in python-telegram-bot/python-telegram-bot#3963 and enables Bot.get_updates to use the default read timeout specified in the request object rather than hard-coding a custom default value.
- same, do_request needs all the httpx timeout params. They dont make sense at all with aiohttp, should I raise an error? I just ignore them anyway lol
IMO you should ensure that aiohttprequest.do_request(…, read_timeout=aiohttprequest.read_timeout) behaves the same as aiohttprequest.do_request(…). If aiohttp has a different set of timeout settings, then you should map our parameters to them as good as possible.
If you do not use all of them, I'd personally recommend to raise a warning (in case the passed value differs from DEFAULT_NONE) but not raise an exception.
I did not look at the tests yet
| from telegram._utils.logging import get_logger | ||
| from telegram._utils.types import ODVInput |
There was a problem hiding this comment.
please do not use ptb internals
There was a problem hiding this comment.
I have to, otherwise I can't check if the parameter is a default instance, or?
There was a problem hiding this comment.
we have https://docs.python-telegram-bot.org/en/stable/telegram.request.baserequest.html#telegram.request.BaseRequest.DEFAULT_NONE in place. for the typing. I would suggest to copy-paste from PTB code if that helps …
There was a problem hiding this comment.
I tried that but then the isinstance call breaks because its not an instance of the copied class, it is of PTB.
There was a problem hiding this comment.
no, I mean coyping the type annotation, not copying the DefaultValue class. for checking if the argument is DEFAULT_NONE, you shoul use if parameter is (not) BaseRequest.DEFAULT_NONE as described in the docs IMO :)
| from typing import Any, Optional, Union | ||
|
|
||
| import aiohttp | ||
| import yarl |
There was a problem hiding this comment.
this is not listed in requirements.txt
There was a problem hiding this comment.
No aiohttp depends on it, it is how they type hint an URL in their library.
Do I need to explicitly add it? Or can I rely on it implicitly, since when they drop it we would realize it in unit tests...
There was a problem hiding this comment.
I'd personally add it as requirement, yes, since you explicitly use it. but on ptbcontrib I'd be okay with skippen, then
| This parameter is intended for advanced users that want to fine-tune the behavior | ||
| of the underlying ``aiohttp`` clientSession. The values passed here will override | ||
| all the defaults set by ``python-telegram-bot`` and all other parameters passed to | ||
| :class:`ClientSession`. The only exception is the :paramref:`media_write_timeout` | ||
| parameter, which is not passed to the client constructor. | ||
| No runtime warnings will be issued about parameters that are overridden in this | ||
| way. |
There was a problem hiding this comment.
please update this. AiohttpRequest is no PTB class and there is also no parameter media_write_timeout here.
There was a problem hiding this comment.
What do you mean with no PTB class? PTB will still pass defaults to this class, and passing this param will override these defaults
There was a problem hiding this comment.
not a class provided through the PTB package. so it's not used in the ApplicationBuilder and the defaults are not set by PTB, but by ptbcontrib :)
There was a problem hiding this comment.
well if I add it like in the ReadMe, applicationbuilder still adds its default timeouts
There was a problem hiding this comment.
No, ApplicationBuilder will not build instances of AiohttpRequest, it doesn't know how to. you'd have to call https://docs.python-telegram-bot.org/en/stable/telegram.ext.applicationbuilder.html#telegram.ext.ApplicationBuilder.request and get_updates_request, passing a ready-build instance.
There was a problem hiding this comment.
yeah okay. Though get_updates does kinda change the timeouts by default, which is a bit unfitting for this module, but it doesn't really matter since it just increases the timeout.
| # this is needed because there are errors if one uses async with or a normal def | ||
| # with ApplicationBuilder, apparently. I am confused. But it works. |
There was a problem hiding this comment.
what is "this" here? I am confused about what you're confused about.
There was a problem hiding this comment.
The try except part around which loop function to use, you need one with the async def situation, and one for with ApplicationBuilder.
There was a problem hiding this comment.
maybe this is related to python-telegram-bot/python-telegram-bot#4875?
There was a problem hiding this comment.
yeah same loop setup there
|
@Poolitzer are you still interested in working on this? |
|
yes just got busy |
Well the issue is basically httpx (and thus PTB usage where someone sets custom timeouts) expects read, write, connect, pool timeout to basically add together to an overall timeout. Aiohttp otoh has a total timeout for everything (hence by default I only set that, and to 15, which is the 5 default timeouts httpx implementation has summed up). Then it has further limits for some other parts of the connection process (for reverence). I will implement it now as you said with a best effort match basis, but for the future it would make more sense to have one "timeout" param and each implementation can decide what they want to pass there in what form. |
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
Bibo-Joshi
left a comment
There was a problem hiding this comment.
I only looked at the diff since my last review. Two minor findings
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
|
Thank you very much for the contribution! |
This is my take on solving python-telegram-bot/python-telegram-bot#4560. I think the implementation is correct, I copied all appropriate httpx tests over.
There are open points I need feedback on:
Implementation:
Tests: