Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove surplus logging from updater network loop #4432

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

Merged

Conversation

MartinHjelmare
Copy link
Contributor

@MartinHjelmare MartinHjelmare commented Aug 18, 2024

Background

When there's a TelegramError in the Updater._network_loop_retry method, the exception is currently both logged and passed to the on_err_cb.

Example log:

2024-08-18 03:11:51.704 ERROR (MainThread) [telegram.ext.Updater] Error while getting Updates: Bad Gateway
2024-08-18 03:11:51.704 ERROR (MainThread) [telegram.ext.Updater] Exception happened while polling for updates.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/telegram/ext/_updater.py", line 742, in _network_loop_retry
    if not await do_action():
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/ext/_updater.py", line 736, in do_action
    return action_cb_task.result()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/ext/_updater.py", line 387, in polling_action_cb
    raise exc
  File "/usr/local/lib/python3.12/site-packages/telegram/ext/_updater.py", line 376, in polling_action_cb
    updates = await self.bot.get_updates(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/_bot.py", line 541, in decorator
    result = await func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/_bot.py", line 4177, in get_updates
    await self._post(
  File "/usr/local/lib/python3.12/site-packages/telegram/_bot.py", line 629, in _post
    return await self._do_post(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/_bot.py", line 657, in _do_post
    return await request.post(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/request/_baserequest.py", line 200, in post
    result = await self._request_wrapper(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/telegram/request/_baserequest.py", line 383, in _request_wrapper
    raise NetworkError(description or "Bad Gateway")
telegram.error.NetworkError: Bad Gateway

Proposed changes

  • I'd like to remove the direct logging of the exception (first log line above), since the error callback also handles the exception. The user of the library is then free to handle the exception as wished, potentially without logging. The default error callback will still log the exception (second log line above) if the user doesn't customizes the error callback.

@MartinHjelmare
Copy link
Contributor Author

MartinHjelmare commented Aug 18, 2024

Remaining CI test failures seem unrelated to the PR change.

Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice finding, thanks for seding a PR!

@Bibo-Joshi Bibo-Joshi merged commit a05362c into python-telegram-bot:master Aug 19, 2024
24 of 25 checks passed
@MartinHjelmare MartinHjelmare deleted the updater-logging-cleanup branch August 19, 2024 17:01
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants