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.

Redis model does not implement __hash__.

See original GitHub issue

Version: 3.4.0

Platform: Python 3.7

Description: in the new version Redis model has __eq__ implemented but not __hash__. Python docs(https://docs.python.org/3/reference/datamodel.html#object.__hash):

if it defines eq() but not hash(), its instances will not be usable as items in hashable collections.

A class that overrides eq() and does not define hash() will have its hash() implicitly set to None. When the hash() method of a class is None, instances of the class will raise an appropriate TypeError when a program attempts to retrieve their hash value, and will also be correctly identified as unhashable when checking isinstance(obj, collections.abc.Hashable).

If a class that overrides eq() needs to retain the implementation of hash() from a parent class, the interpreter must be told this explicitly by setting hash = <ParentClass>.hash.

Shouldn’t Redis implement __hash__ then?

There is an issue with kombu related to it: https://github.com/celery/kombu/issues/1152

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
dominik-blncommented, Jan 31, 2020

We are encountering the same problem when updating our Celery workers from 3.3.11 to v3.4.0:

[2020-01-31 12:22:49,722: CRITICAL/MainProcess] Unrecoverable error: TypeError("unhashable type: 'Redis'")
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/worker/worker.py", line 205, in start
    self.blueprint.start(self)
  File "/usr/local/lib/python3.7/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/usr/local/lib/python3.7/site-packages/celery/bootsteps.py", line 369, in start
    return self.obj.start()
  File "/usr/local/lib/python3.7/site-packages/celery/worker/consumer/consumer.py", line 318, in start
    blueprint.start(self)
  File "/usr/local/lib/python3.7/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/usr/local/lib/python3.7/site-packages/celery/worker/consumer/mingle.py", line 40, in start
    self.sync(c)
  File "/usr/local/lib/python3.7/site-packages/celery/worker/consumer/mingle.py", line 44, in sync
    replies = self.send_hello(c)
  File "/usr/local/lib/python3.7/site-packages/celery/worker/consumer/mingle.py", line 57, in send_hello
    replies = inspect.hello(c.hostname, our_revoked._data) or {}
  File "/usr/local/lib/python3.7/site-packages/celery/app/control.py", line 154, in hello
    return self._request('hello', from_node=from_node, revoked=revoked)
  File "/usr/local/lib/python3.7/site-packages/celery/app/control.py", line 106, in _request
    pattern=self.pattern, matcher=self.matcher,
  File "/usr/local/lib/python3.7/site-packages/celery/app/control.py", line 477, in broadcast
    limit, callback, channel=channel,
  File "/usr/local/lib/python3.7/site-packages/kombu/pidbox.py", line 352, in _broadcast
    channel=chan)
  File "/usr/local/lib/python3.7/site-packages/kombu/pidbox.py", line 391, in _collect
    self.connection.drain_events(timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/kombu/connection.py", line 323, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kombu/transport/virtual/base.py", line 963, in drain_events
    get(self._deliver, timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/kombu/transport/redis.py", line 374, in get
    self._register_BRPOP(channel)
  File "/usr/local/lib/python3.7/site-packages/kombu/transport/redis.py", line 311, in _register_BRPOP
    if not self._client_registered(channel, channel.client, 'BRPOP'):
  File "/usr/local/lib/python3.7/site-packages/kombu/transport/redis.py", line 306, in _client_registered
    (channel, client, cmd) in self._chan_to_sock)
TypeError: unhashable type: 'Redis'
10reactions
andymccurdycommented, Jan 31, 2020

I’ll have this fixed later today including a 3.4.1 release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Manage Hashes in Redis - DigitalOcean
To create a hash, run the hset command. This command accepts the name of the hash key, the field string, and the corresponding...
Read more >
1.2.4 Hashes in Redis
Whereas LIST s and SET s in Redis hold sequences of items, Redis HASH es store a mapping of keys to values. The...
Read more >
Redis hashes
Redis hashes are record types structured as collections of field-value pairs. You can use hashes to represent basic objects and to store groupings...
Read more >
Redis HashKey erroring out - Stack Overflow
Calling any hash command (including hset ) will fail if the value is not a hash - so if it already exists as...
Read more >
Hash Slot vs. Consistent Hashing in Redis - Severalnines
Consistent hashing and hash slots are algorithms that would suffice as far as sufficient distributing of keys that serve to be cached to...
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