cqlengine connection set_session()不处理不同的键空间

2024-05-14 07:23:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码

from cassandra.cqlengine import connection


#inside a flask function
session = get_session_for_keyspace(keyspace)
connection.set_session(session)

object_list = ModelTable.objects.filter(....)

但是,尽管会话“指向”了正确的键空间,但是ModelTable中filter执行的select使用了之前定义的一些行的旧keypsace。如何使模型使用每次为连接设置的会话?在


Tags: 代码fromimportflaskforgetsessionfunction
1条回答
网友
1楼 · 发布于 2024-05-14 07:23:57

Apostolos,它正在使用您的会话,但是在第一次调用set_session方法时会设置默认的键空间。请看这里cquengine,connection类中的代码。我猜您的模型没有定义键空间,因此使用默认键空间。在

https://github.com/datastax/python-driver/blob/master/cassandra/cqlengine/connection.py#L85-88

如果您在不同的键空间中使用不同的模型,并且只是尝试切换connection类。您可以在您的模型中定义一个默认的键空间,在这种特定情况下也可以使用。在

您的模型需要在类级别重写此值。 https://github.com/datastax/python-driver/blob/master/cassandra/cqlengine/models.py#L311

在多个cassandra键空间中使用相同的模型有点像是在对抗cquengine当前的实现方式。如果可能的话,我建议您考虑使用基本驱动程序。在

相关问题 更多 >

    热门问题