Skip to content Skip to sidebar Skip to footer

Typeerror: Unhashable Type Usertype When Creating A Cassandra Python Driver Model With A Set Of A Udt

This issue is regarding the object mapper of the Datastax Cassandra python driver. When trying to create a Model with a 'Set' of UDT as a field, I get the error: TypeError: unhasha

Solution 1:

This is possible in Cassandra (and using the core driver directly), but the cqlengine mapper does not support it presently. The reason is a legacy API limitation, where the mapper normalizes to basic python types for sets and maps. The API thus has the same requirement of hashability for set elements and map keys.

We have a ticket open here, but it will need to wait for the next major release since it means a change in API.

You might try working around this by providing a hash on your UDT model class (if it makes sense).

Solution 2:

Extending from Adam, to use hash on UserType

classClient(UserType):
   mac = columns.Text()
   rx = columns.Integer()
   tx = columns.Integer()

   def__hash__(self):
      returnhash((self.mac, self.rx, self.tx))

Thank you Adam.

Post a Comment for "Typeerror: Unhashable Type Usertype When Creating A Cassandra Python Driver Model With A Set Of A Udt"