question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chat.update_chat() fails for private chats obtained from Bot.get_chat()

See original GitHub issue

Context

  • Operating System: Windows 10
  • Python Version: 3.9.0
  • aiogram version: 2.11.2
  • aiohttp version: 3.7.3
  • uvloop version (if installed): N/A

Expected Behavior

Chat is updated successfully.

Current Behavior

A TypeError is raised.

Failure Information (for bugs)

Steps to Reproduce

  1. Run the following code
import logging

from aiogram import Bot, Dispatcher, executor, types

logging.basicConfig(level=logging.INFO)
bot = Bot(token="TOKEN HERE")
dp = Dispatcher(bot)


@dp.message_handler(commands="test")
async def test(message: types.Message) -> None:
    # No error if the following line is replaced with chat = message.chat
    chat = await bot.get_chat(message.chat.id)
    await chat.update_chat()  # Error in this function call


if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)

  1. Send /test to the bot in its DMs or a private supergroup.

Failure Logs

Traceback (most recent call last):
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\dispatcher\dispatcher.py", line 388, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\dispatcher\dispatcher.py", line 225, in process_updates
    return await asyncio.gather(*tasks)
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\dispatcher\dispatcher.py", line 246, in process_update
    return await self.message_handlers.notify(update.message)
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\test\aiogramtest.py", line 14, in test
    await chat.update_chat()
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\types\chat.py", line 123, in update_chat
    self[key] = value
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\types\base.py", line 226, in __setitem__
    return self.props[key].set_value(self, value, self.conf.get('parent', None))
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\types\fields.py", line 57, in set_value
    value = self.deserialize(value, parent)
  File "C:\Users\jono\AppData\Roaming\Python\Python39\site-packages\aiogram\types\fields.py", line 114, in deserialize
    parent = weakref.ref(parent)
TypeError: cannot create weak reference to 'NoneType' object

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
darksidecatcommented, Mar 27, 2021

did dome investigation:

print(message.chat.values) ↴
{'id': Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…, 'first_name': 'Ρ…Ρ…Ρ…', 'last_name': 'Ρ…Ρ…Ρ…', 'type': 'private'}

chat = await bot.get_chat(message.chat.id)
print(chat.values) ↴
{'id': Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…Ρ…, 'first_name': 'Ρ…Ρ…Ρ…', 'last_name': 'Ρ…Ρ…Ρ…', 'type': 'private', 'photo': <aiogram.types.chat_photo.ChatPhoto object at 0x00000235408C2EE0>}

difference is in photo value that can`t be deserialize properly, as far as I understand

also here some detailed logs

  File "C:/Users/Darksidecat/PycharmProjects/aiogram-tests\main.py", line 21, in test
    await chat2.update_chat()  # Error in this function call
          β”‚     β”” <function Chat.update_chat at 0x0000021E92F7B9D0>
          β”” <aiogram.types.chat.Chat object at 0x0000021E931B5C40>
  File "C:\Users\Darksidecat\anaconda3\envs\aiogram-tests\lib\site-packages\aiogram\types\chat.py", line 125, in update_chat
    self[key] = value
    β”‚    β”‚      β”” {'small_file_id': 'AQADAgADq6cxG0bcJhIACLqdo5YuAAMCAANG3CYSAASQcbFK5jlIMuprAAIeBA', 'small_file_unique_id': 'AQADup2jli4AA-pr...
    β”‚    β”” 'photo'
    β”” <aiogram.types.chat.Chat object at 0x0000021E931B5C40>
  File "C:\Users\Darksidecat\anaconda3\envs\aiogram-tests\lib\site-packages\aiogram\types\base.py", line 230, in __setitem__
    return self.props[key].set_value(self, value, self.conf.get('parent', None))
           β”‚    β”‚     β”‚              β”‚     β”‚      β”‚    β”” <property object at 0x0000021E92CC2C20>
           β”‚    β”‚     β”‚              β”‚     β”‚      β”” <aiogram.types.chat.Chat object at 0x0000021E931B5C40>
           β”‚    β”‚     β”‚              β”‚     β”” {'small_file_id': 'AQADAgADq6cxG0bcJhIACLqdo5YuAAMCAANG3CYSAASQcbFK5jlIMuprAAIeBA', 'small_file_unique_id': 'AQADup2jli4AA-pr...
           β”‚    β”‚     β”‚              β”” <aiogram.types.chat.Chat object at 0x0000021E931B5C40>
           β”‚    β”‚     β”” 'photo'
           β”‚    β”” <property object at 0x0000021E92CC2C70>
           β”” <aiogram.types.chat.Chat object at 0x0000021E931B5C40>
  File "C:\Users\Darksidecat\anaconda3\envs\aiogram-tests\lib\site-packages\aiogram\types\fields.py", line 57, in set_value
    value = self.deserialize(value, parent)
            β”‚    β”‚           β”‚      β”” None
            β”‚    β”‚           β”” {'small_file_id': 'AQADAgADq6cxG0bcJhIACLqdo5YuAAMCAANG3CYSAASQcbFK5jlIMuprAAIeBA', 'small_file_unique_id': 'AQADup2jli4AA-pr...
            β”‚    β”” <function Field.deserialize at 0x0000021E92CC5820>
            β”” <aiogram.types.fields.Field object at 0x0000021E92F77AF0>
  File "C:\Users\Darksidecat\anaconda3\envs\aiogram-tests\lib\site-packages\aiogram\types\fields.py", line 114, in deserialize
    parent = weakref.ref(parent)
             β”‚       β”‚   β”” None
             β”‚       β”” <class 'weakref'>
             β”” <module 'weakref' from 'C:\\Users\\Darksidecat\\anaconda3\\envs\\aiogram-tests\\lib\\weakref.py'>

Unfortunately, I can’t help you anymore due to lack of knowledge.

1reaction
darksidecatcommented, Apr 28, 2021

Maybe change default value from None to self in this code will fix this?

@JrooTJunior Should I look further for the cause of the bug? Or that can be the solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Telegram bot get chat informations python - Stack Overflow
because I get little information from getupdates I want to know some info like member IDs and messages IDs etc. in each group...
Read more >
Failed to send in Microsoft Teams Private Chat
I have a question regarding failed to send messages in a Private Chat of Microsoft Teams. I tried to add Microsoft Forms to...
Read more >
chat.update method - Slack API
This method updates a message in a channel. Though related to chat.postMessage , some parameters of chat.update are handled differently.
Read more >
telegram.Chat - python-telegram-bot v20.0b0
If set, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in telegram.Bot.get_chat() . New in version...
Read more >
tgbotapi - Go Packages
For private chats, this // update is received only when the bot is ... func (bot *BotAPI) GetChat(config ChatInfoConfig) (Chat, error).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found