Skip to content

'InputPaidMedia' object has no attribute 'parse_mode' #4753

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

Closed
ngrogolev opened this issue Apr 11, 2025 · 3 comments · Fixed by #4761
Closed

'InputPaidMedia' object has no attribute 'parse_mode' #4753

ngrogolev opened this issue Apr 11, 2025 · 3 comments · Fixed by #4761
Labels
⚙️ bot-api affected functionality: bot-api

Comments

@ngrogolev
Copy link
Contributor

Steps to Reproduce

  1. Initialize the application with default settings, including a parse_mode key
  2. Attempt to call send_paid_media with the Sequence of InputPaidMedia in media parameter

Expected behaviour

The send_paid_media method should successfully send the specified paid media to the target chat using the default parse_mode

Actual behaviour

Sending the media fails with an exception::
AttributeError: 'InputPaidMedia' object has no attribute 'parse_mode'

Operating System

Linux

Version of Python, python-telegram-bot & dependencies

python-telegram-bot 22.0
Bot API 8.3
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)]

Relevant log output

Traceback (most recent call last):
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_application.py", line 1298, in process_update
    await coroutine
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_handlers/conversationhandler.py", line 842, in handle_update
    new_state: object = await handler.handle_update(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_handlers/basehandler.py", line 158, in handle_update
    return await self.callback(update, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/bot/handlers/producer/producer_media_handler.py", line 110, in set_price_handler
    paid_media_message = await context.bot.send_paid_media(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_extbot.py", line 4385, in send_paid_media
    return await super().send_paid_media(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/_bot.py", line 9675, in send_paid_media
    return await self._send_message(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_extbot.py", line 618, in _send_message
    result = await super()._send_message(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/_bot.py", line 803, in _send_message
    result = await self._post(
             ^^^^^^^^^^^^^^^^^
  File "/path/to/the/project/.venv/lib/site-packages/telegram/_bot.py", line 686, in _post
    self._insert_defaults(data)
  File "/path/to/the/project/.venv/lib/site-packages/telegram/ext/_extbot.py", line 473, in _insert_defaults
    if media.parse_mode is DEFAULT_NONE:
       ^^^^^^^^^^^^^^^^
AttributeError: 'InputPaidMedia' object has no attribute 'parse_mode'

Additional Context

No response

@ngrogolev ngrogolev added the 📋 triage work status: triage label Apr 11, 2025
@Bibo-Joshi
Copy link
Member

@ngrogolev Hi. Thanks for your report!
It looks like ExtBot._insert_defaults wrongly assumes in line 469 that all elements in the list are of type InputMedia. Properly testing this was probably not done so far b/c testing paid stuff is not directly possible for us …
the fix would be to apply an

if not isinstance(…, InputMedia):
    continue

for tests, we would have to try to to apply mocks to send_paid_media so that we can check that this works with defaults.

Would you be interested on sending a PR yourself? We can ofc help

@Bibo-Joshi Bibo-Joshi added ⚙️ bot-api affected functionality: bot-api and removed 📋 triage work status: triage labels Apr 11, 2025
@ngrogolev
Copy link
Contributor Author

@Bibo-Joshi, sure thing, I can send a PR. However, I can start working on this issue only next week.

If that's okay, I'll take on this task

@Bibo-Joshi
Copy link
Member

Sure, looking forward to it :) let us know if you need help

@github-actions github-actions bot locked and limited conversation to collaborators Apr 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ bot-api affected functionality: bot-api
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants