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.setterView on GitHub (pinned to d3b69d2e9f)
Solutions
- Include all fallbacks in the constructor's fallbacks list
- 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
- Declare all fallbacks up front
- Rebuild handler if fallback list changes
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
- You can not assign a new value to entry_points after initial
- You can not assign a new value to states after initializatio
- You can not assign a new value to allow_reentry after initia
- You can not assign a new value to per_user after initializat
- You can not assign a new value to per_chat after initializat
AI-assisted analysis of python-telegram-bot/python-telegram-bot@d3b69d2e9f (2026-08-28).
Data as JSON: /api/errors/b0de35118f32cd1f.
Report an issue: GitHub.