{"record":{"id":"a1874044efcb3535","repo":"python-telegram-bot/python-telegram-bot","slug":"the-entity-is-neither-message-nor-update-got-ty","errorCode":null,"errorMessage":"The entity is neither Message nor Update (got: {type(entity)})","messagePattern":"The entity is neither Message nor Update \\(got: (.+?)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/telegram/helpers.py","lineNumber":140,"sourceCode":"    Returns:\n        :obj:`str` | :obj:`None`: One of :class:`telegram.constants.MessageType` if the entity\n        contains a message that matches one of those types. :obj:`None` otherwise.\n\n    \"\"\"\n    # Importing on file-level yields cyclic Import Errors\n    from telegram import (  # pylint: disable=import-outside-toplevel  # noqa: PLC0415\n        Message,\n        Update,\n    )\n\n    if isinstance(entity, Message):\n        message = entity\n    elif isinstance(entity, Update):\n        if not entity.effective_message:\n            return None\n        message = entity.effective_message\n    else:\n        raise TypeError(f\"The entity is neither Message nor Update (got: {type(entity)})\")\n\n    for message_type in MessageType:\n        if message[message_type]:\n            return message_type\n\n    return None\n\n\ndef create_deep_linked_url(\n    bot_username: str, payload: str | None = None, group: bool = False\n) -> str:\n    \"\"\"\n    Creates a deep-linked URL for this :paramref:`~create_deep_linked_url.bot_username` with the\n    specified :paramref:`~create_deep_linked_url.payload`. See\n    https://core.telegram.org/bots/features#deep-linking to learn more.\n\n    The :paramref:`~create_deep_linked_url.payload` may consist of the following characters:\n    ``A-Z, a-z, 0-9, _, -``","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/python-telegram-bot/python-telegram-bot/blob/d3b69d2e9fb7af6c796f84516cfda751752c7cb7/src/telegram/helpers.py#L122-L158","documentation":"Raised by telegram.helpers.effective_message_type when the entity argument is neither a Message nor an Update instance. The function inspects the entity's attributes to determine which MessageType it contains, so it must receive one of those two types. Any other object (e.g. a CallbackQuery, User, or str) triggers this TypeError.","triggerScenarios":"Calling effective_message_type(entity) with anything other than telegram.Message or telegram.Update, e.g. passing update.callback_query or a plain string.","commonSituations":"Passing the wrong sub-object of an Update (like update.channel_post vs update itself), or refactoring handlers so a non-Update object reaches this helper.","solutions":["Pass update directly instead of a sub-object like update.callback_query or update.message where message may be None","If you have a CallbackQuery, use entity.message instead","Type-check before calling: isinstance(entity, (Message, Update))"],"exampleFix":"// before\ntype_ = effective_message_type(update.callback_query)\n// after\ntype_ = effective_message_type(update)  # or update.callback_query.message","handlingStrategy":"type-guard","validationCode":"from telegram import Message, Update\nif not isinstance(entity, (Message, Update)):\n    raise TypeError(f'unsupported entity: {type(entity)}')","typeGuard":"from telegram import Message, Update\n\ndef is_message_or_update(e: object) -> bool:\n    return isinstance(e, (Message, Update))","tryCatchPattern":"try:\n    t = effective_message_type(entity)\nexcept TypeError as e:\n    logger.warning('unsupported entity: %s', e)\n    t = None","preventionTips":["Always pass the whole Update from handlers","Type-check inputs when the entity comes from dynamic dispatch"],"tags":["python","telegram-bot","type-error","argument-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"d3b69d2e9fb7af6c796f84516cfda751752c7cb7","analyzedAt":"2026-08-28T16:18:54.805Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}