For someone who stumbles upon the same problem and needs a solution.
Please keep in mind this is a workaround so if a proper solution pops up here please follow that.
This Solution is based on the assumption:
- You are using cassandra-driver==3.11.0 or lower, where connection
registry is supported (Take a look here)
- You have 2 or more clusters to handle and you have registered all named connections though the above API (register_connection). Make one of the connections default connection.
A little background about your problem:
When you use a ModelSetQuery
object with different connections, it exhibits expected behaviour. So if you have a query like:
MyModel.filter(u_id=u_id).first()
You could easily specify the keyspace
and the connection
for such a Query with the using
method:
MyModel.filter(u_id=u_id).using(keyspace=KEYSPACE, connection=connection).first()
You will observe that however MyModel.using(connection=connection).save()
does not work.
For the critically minded:
You will observe that underneath _execute_statement
method in cassandra.cqlengine.query
has the connection
variable as None
and even though you set with Model.__connection__
the model._get_connection()
does not grab your connection name string. Just a Hint to get you started to look at the actual problem.
WORKAROUND SOLUTION: group your operations on each cluster together and before each cluster operation switch default connection to the appropriate cluster with connection.set_default_connection("cluster_connection_name")
So basically:
connection.set_default_connection("cluster1")
# operations and queries on cluster 1
....
connection.set_default_connection("cluster2")
# operations and queries on cluster 2
....
Hope this helps!