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.

telethon.tl.types.Message is unhashable after upgraded to 0.17+

See original GitHub issue

After upgrade from 0.16.2.x to 0.17+, our App broken due to telethon.tl.types.Message become unhashable. Following is a simple test case to reproduce this issue:

from telethon.tl.types import Message

print('Message.__hash__:', Message.__hash__)
msg = Message(1, None, None, 'Testing 1')
testSet = set([msg])
testSet |= set([msg])
print('testSet: ', testSet)

Output from 0.16.2.3:

telethon-0.16.2.3>pip3 install telethon==0.16.2.3
telethon-0.16.2.3>test_case.py
Message.__hash__: <slot wrapper '__hash__' of 'object' objects>
testSet:  {<telethon.tl.types.Message object at 0x017B0BF0>}

Output from 0.17.4.5:

telethon-0.16.2.3>pip3 install telethon==0.17.4.5
telethon-0.17.4.5>test_case.py
Message.__hash__: None
Traceback (most recent call last):
  File "...\test_case.py", line 5, in <module>
    testSet = set([msg])
TypeError: unhashable type: 'Message'

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Lonamicommented, Mar 1, 2018

I was unaware TLObjects ever were hashable. You can obj.to_dict() instead and pick what you need. Or make a dict by {msg.id: msg}.

0reactions
Lonamicommented, Mar 19, 2018

Your solution then is {id(obj): obj} and .update() it, or setting TLObject.__hash__ = lambda self: id(self).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle Unhashable Type List Exceptions in Python
The Python TypeError: Unhashable Type: 'list' happens when a mutable list, instead of an immutable tuple, is used as a hash argument.
Read more >
How to use the telethon.tl.types.Message function in ... - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately. message = types. Message( id=777,...
Read more >
ChangeLog - ftp
4 with following changes: * Make the binaries built in the unprivileged apptainer package relocatable. When moving the binaries to a new location,...
Read more >
TypeError : Unhashable type - python - Stack Overflow
A list is unhashable because its contents can change over its lifetime. You can update an item contained in the list at any...
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