python-telegram-bot/python-telegram-bot · error · AttributeError

You can not assign a new value to fallbacks after initializa

Error message

You can not assign a new value to fallbacks after initialization.

What it means

ConversationHandler.fallbacks is read-only after initialization; assigning handler.fallbacks = [...] raises AttributeError. The fallback handler list is fixed in _fallbacks at construction time.

Source

Thrown at src/telegram/ext/_handlers/conversationhandler.py:487

        associated :obj:`BaseHandler` objects that should be used in that state.
        """
        return self._states

    @states.setter
    def states(self, _: object) -> NoReturn:
        raise AttributeError("You can not assign a new value to states after initialization.")

    @property
    def fallbacks(self) -> list[BaseHandler[Update, CCT, object]]:
        """list[:class:`telegram.ext.BaseHandler`]: A list of handlers that might be used if
        the user is in a conversation, but every handler for their current state returned
        :obj:`False` on :meth:`check_update`.
        """
        return self._fallbacks

    @fallbacks.setter
    def fallbacks(self, _: object) -> NoReturn:
        raise AttributeError("You can not assign a new value to fallbacks after initialization.")

    @property
    def allow_reentry(self) -> bool:
        """:obj:`bool`: Determines if a user can restart a conversation with an entry point."""
        return self._allow_reentry

    @allow_reentry.setter
    def allow_reentry(self, _: object) -> NoReturn:
        raise AttributeError(
            "You can not assign a new value to allow_reentry after initialization."
        )

    @property
    def per_user(self) -> bool:
        """:obj:`bool`: If the conversation key should contain the User's ID."""
        return self._per_user

    @per_user.setter

View on GitHub (pinned to d3b69d2e9f)

Solutions

  1. Include all fallbacks in the constructor's fallbacks list
  2. Rebuild the ConversationHandler and re-register it if fallbacks must change

Example fix

# before
conv.fallbacks = [CommandHandler('cancel', cancel)]  # raises
# after
conv = ConversationHandler(entry, states, [CommandHandler('cancel', cancel)])
Defensive patterns

Strategy: type-guard

Validate before calling

def build(entry, states, fallbacks, **kw):
    return ConversationHandler(entry, states, fallbacks, **kw)

Try / catch

try:
    conv.fallbacks = [fb]
except AttributeError:
    conv = ConversationHandler(conv.entry_points, conv.states, [fb])

Prevention

When it happens

Trigger: handler.fallbacks = [CommandHandler('cancel', cancel_cb)] on an existing instance.

Common situations: Deciding to add a cancel/stop command after handler construction, or configuration-driven bot setups that try to patch handlers after registration.

Related errors


AI-assisted analysis of python-telegram-bot/python-telegram-bot@d3b69d2e9f (2026-08-28). Data as JSON: /api/errors/b0de35118f32cd1f. Report an issue: GitHub.