Skip to content

fix(telegram): catch AttributeError from PTB python-3.11 __slots__ conflict with actionable message - #64773

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/64730-telegram-httpxrequest-readonly
Closed

fix(telegram): catch AttributeError from PTB python-3.11 __slots__ conflict with actionable message#64773
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/64730-telegram-httpxrequest-readonly

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #64730

Summary

On Python 3.11, a CPython interaction between abc.abstractmethod and __slots__ in PTB's HTTPXRequest class makes the do_request attribute read-only. When the Telegram adapter's connect() calls Application.initialize(), the abstract-method/slots conflict raises:

'HTTPXRequest' object attribute 'do_request' is read-only

This is a closed issue in CPython resolved in Python 3.12+, but users on Python 3.11 (especially Windows) hit it when running the Telegram gateway.

Fix

Convert the opaque AttributeError into a clear OSError with an actionable message suggesting:

  • Ensuring the pinned PTB version (==22.6) is installed
  • Upgrading to Python 3.12+

Test Plan

  • test_telegram_start_polling_timeout.py: 4/4 passed
  • test_telegram_init_deadline.py: 6/6 passed
  • test_telegram_closewait_limits_31599.py + test_telegram_conflict.py + test_telegram_network.py: 63/63 passed

@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter P1 High — major feature broken, no workaround sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jul 15, 2026
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as redundant — this bug was already fixed on main in PR #64574 (commit f5f79ff, merged ~1 hour before this PR opened).

The 'HTTPXRequest' object attribute 'do_request' is read-only error came from our adapter's _instrument_polling_request doing an instance-level request.do_request = wrapper assignment, which PTB 22.6's slotted HTTPXRequest rejects on Python 3.13+ (where AbstractAsyncContextManager added __slots__ = (), removing the instance __dict__).

The fix in #64574 replaced the instance assignment with a __class__ swap to a __slots__ = () subclass that overrides do_request — no assignment, no AttributeError. The error cannot occur on current main.

Thanks for the contribution @kyssta-exe — the error message you wrote would have been helpful for users hitting this before the fix landed. The underlying issue (#64482 / #64730) is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ✗ telegram failed to connect

3 participants