Skip to content

get_forum_topics crashes on ForumTopicDeleted objects #71

@Barabashka656

Description

@Barabashka656

Checklist

  • I am sure the error is coming from Hydrogram's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install -U https://github.com/hydrogram/hydrogram/archive/dev.zip and reproduced the issue using the latest development version

Description

Operating system
Windows 10
Debian GNU/Linux 12 (bookworm)

Python version
3.13.5

hydrogram version
0.2.0

When calling get_forum_topics on a forum chat that contains deleted topics, Hydrogram crashes with an AttributeError. It tries to parse ForumTopicDeleted objects as if they were ForumTopic, but those don’t have the same attributes.

what happens if you add logging to the topic parsing in the get_forum_topics function:

for _topic in r.topics:
    try:
        yield types.ForumTopic._parse(_topic)
    except Exception as e:
        print(f"error_parse: {_topic.__class__}")

logs:
error_parse: <class 'hydrogram.raw.types.forum_topic_deleted.ForumTopicDeleted'>

Steps to reproduce

  1. Create client as user
  2. Invoke get_forum_topics on a forum chat that contains deleted topics

Code example

import asyncio
from hydrogram import Client
from hydrogram.types import ForumTopic

API_ID = 
API_HASH = 
CHAT_ID = -1233 # forum chat with deleted topics

async def main():
    async with Client("my_session", api_id=API_ID, api_hash=API_HASH) as app:
        async for topic in app.get_forum_topics(CHAT_ID):
            pass

asyncio.run(main())

Logs

Windows:

F:\projects\big_projects\test_hydro>f:/projects/big_projects/test_hydro/.venv/Scripts/python.exe f:/projects/big_projects/test_hydro/main.py
Traceback (most recent call last):
  File "f:\projects\big_projects\test_hydro\main.py", line 49, in <module>    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\runners.py", line 195, in run      
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\runners.py", line 118, in run      
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "f:\projects\big_projects\test_hydro\main.py", line 37, in main    
    async for topic in topics:
        pass
  File "f:\projects\big_projects\test_hydro\.venv\Lib\site-packages\hydrogram\methods\chats\get_forum_topics.py", line 71, in get_forum_topics
    yield types.ForumTopic._parse(_topic)
          ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "f:\projects\big_projects\test_hydro\.venv\Lib\site-packages\hydrogram\types\user_and_chats\forum_topic.py", line 127, in _parse
    from_id = forum_topic.from_id
              ^^^^^^^^^^^^^^^^^^^
AttributeError: 'ForumTopicDeleted' object has no attribute 'from_id'

Linux:
Traceback (most recent call last):
  File "/app/main.py", line 51, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/app/main.py", line 39, in main
    async for topic in topics:
        pass
  File "/usr/local/lib/python3.13/site-packages/hydrogram/methods/chats/get_forum_topics.py", line 71, in get_forum_topics
    yield types.ForumTopic._parse(_topic)
          ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/hydrogram/types/user_and_chats/forum_topic.py", line 127, in _parse
    from_id = forum_topic.from_id
              ^^^^^^^^^^^^^^^^^^^
AttributeError: 'ForumTopicDeleted' object has no attribute 'from_id'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions