TypeError:使用UDT集创建Cassandra Python驱动程序模型时,无法散列的类型UserType [英] TypeError: Unhashable type UserType when creating a Cassandra Python driver model with a Set of a UDT

查看:90
本文介绍了TypeError:使用UDT集创建Cassandra Python驱动程序模型时,无法散列的类型UserType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与Datastax Cassandra python驱动程序的对象映射器有关.尝试使用UDT的集合"作为字段创建模型时,出现错误:TypeError:不可散列的类型:'[UdtClassName]'

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: unhashable type: '[UdtClassName]'

但是,我能够创建具有基本类型(例如文本)的Set的模型或具有UDT列表的模型.

However, I am able to create a Model with a Set of a basic type (e.g. Text) or a Model with a List of UDT.

请注意,这个问题似乎仅存在于对象映射器中,因为我能够使用CQL查询在Cassandra中创建UDT集.

Note that this is issue seem to exist only with the object mapper since I am able to create sets of UDTs in Cassandra using CQL queries.

任何人以前都遇到过此问题吗?有人有建议吗?

Anyone has encountered this problem before? Anyone has an advice?

我正在使用python 3.4.4运行cassandra python驱动程序3.2.2

I am running cassandra python driver 3.2.2, with python 3.4.4

推荐答案

在Cassandra中(可以直接使用核心驱动程序),这是可能的,但是cqlengine映射器目前不支持它.原因是传统的API限制,其中映射器将规范化为集合和映射的基本python类型.因此,API对集合元素和映射键具有相同的散列性要求.

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.

我们在此处打开了一个票证,但需要等待下一个主要版本,因为它意味着API发生了变化.

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

您可以尝试通过在UDT模型类上提供哈希值来解决此问题(如果有意义).

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

这篇关于TypeError:使用UDT集创建Cassandra Python驱动程序模型时,无法散列的类型UserType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆