You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Bimal Gangawal <bi...@gmail.com> on 2020/05/15 09:00:22 UTC
using() not able to switch keyspace on the fly.
Hi,
I am new to cassandra and using python to insert data into cassandra
(cassandra-driver==3.23.0).
https://docs.datastax.com/en/developer/python-driver/3.23/cqlengine/connections/
In
this document i found that we can use using() method to change the keyspace
and connection on the fly but while doing the same i ended up with below
error
i have a table DataModel() class through which i have defined the table as
ORM
datamodel = DataModel()
....
datamodel.using(keyspace="tb1").save()
TypeError: using_setter() got an unexpected keyword argument 'keyspace'
After looking at the source i found that using() only takes connection
and not keyspace as parameter.
What is the alternative to achieve this?
Please correct me if i am wrong.
Thanks
-Bimal
Re: using() not able to switch keyspace on the fly.
Posted by Alan Boudreault <al...@datastax.com>.
You can use `DataModel.objects.using().create()` or use another model for
this purpose. See the ContextQuery utility:
https://docs.datastax.com/en/developer/python-driver/3.23/cqlengine/connections/#context-manager
https://docs.datastax.com/en/developer/python-driver/3.23/api/cassandra/cqlengine/query/#cassandra.cqlengine.query.ContextQuery
On Sun, May 17, 2020 at 3:17 PM Bimal Gangawal <bi...@gmail.com>
wrote:
> But I am not able to save the row here using
> datamodel.objects.using(keyspace="tb1").save()
>
> What is the preferred alternative to achieve this ?
>
> On Sat, May 16, 2020, 7:37 AM Alan Boudreault <
> alan.boudreault@datastax.com> wrote:
>
>> Hello Bimal,
>>
>> Due to some internal limitations, you can only switch the keyspace on the
>> fly of a ModelQuerySet, not a model instance. This should work:
>>
>> DataModel.objects.using(keyspace="tb1")
>>
>> Alan
>>
>> On Fri, May 15, 2020 at 5:00 AM Bimal Gangawal <bi...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> I am new to cassandra and using python to insert data into cassandra
>>> (cassandra-driver==3.23.0).
>>>
>>> https://docs.datastax.com/en/developer/python-driver/3.23/cqlengine/connections/ In
>>> this document i found that we can use using() method to change the keyspace
>>> and connection on the fly but while doing the same i ended up with below
>>> error
>>>
>>> i have a table DataModel() class through which i have defined the table
>>> as ORM
>>> datamodel = DataModel()
>>> ....
>>> datamodel.using(keyspace="tb1").save()
>>>
>>> TypeError: using_setter() got an unexpected keyword argument 'keyspace'
>>>
>>>
>>> After looking at the source i found that using() only takes connection and not keyspace as parameter.
>>>
>>> What is the alternative to achieve this?
>>>
>>> Please correct me if i am wrong.
>>> Thanks
>>>
>>>
>>> -Bimal
>>>
>>>
>>
>> --
>> Alan Boudreault
>> e. alan.boudreault@datastax.com
>> w. www.datastax.com
>>
>>
--
Alan Boudreault
e. alan.boudreault@datastax.com
w. www.datastax.com
Re: using() not able to switch keyspace on the fly.
Posted by Bimal Gangawal <bi...@gmail.com>.
But I am not able to save the row here using
datamodel.objects.using(keyspace="tb1").save()
What is the preferred alternative to achieve this ?
On Sat, May 16, 2020, 7:37 AM Alan Boudreault <al...@datastax.com>
wrote:
> Hello Bimal,
>
> Due to some internal limitations, you can only switch the keyspace on the
> fly of a ModelQuerySet, not a model instance. This should work:
>
> DataModel.objects.using(keyspace="tb1")
>
> Alan
>
> On Fri, May 15, 2020 at 5:00 AM Bimal Gangawal <bi...@gmail.com>
> wrote:
>
>> Hi,
>>
>> I am new to cassandra and using python to insert data into cassandra
>> (cassandra-driver==3.23.0).
>>
>> https://docs.datastax.com/en/developer/python-driver/3.23/cqlengine/connections/ In
>> this document i found that we can use using() method to change the keyspace
>> and connection on the fly but while doing the same i ended up with below
>> error
>>
>> i have a table DataModel() class through which i have defined the table
>> as ORM
>> datamodel = DataModel()
>> ....
>> datamodel.using(keyspace="tb1").save()
>>
>> TypeError: using_setter() got an unexpected keyword argument 'keyspace'
>>
>>
>> After looking at the source i found that using() only takes connection and not keyspace as parameter.
>>
>> What is the alternative to achieve this?
>>
>> Please correct me if i am wrong.
>> Thanks
>>
>>
>> -Bimal
>>
>>
>
> --
> Alan Boudreault
> e. alan.boudreault@datastax.com
> w. www.datastax.com
>
>
Re: using() not able to switch keyspace on the fly.
Posted by Alan Boudreault <al...@datastax.com>.
Hello Bimal,
Due to some internal limitations, you can only switch the keyspace on the
fly of a ModelQuerySet, not a model instance. This should work:
DataModel.objects.using(keyspace="tb1")
Alan
On Fri, May 15, 2020 at 5:00 AM Bimal Gangawal <bi...@gmail.com>
wrote:
> Hi,
>
> I am new to cassandra and using python to insert data into cassandra
> (cassandra-driver==3.23.0).
>
> https://docs.datastax.com/en/developer/python-driver/3.23/cqlengine/connections/ In
> this document i found that we can use using() method to change the keyspace
> and connection on the fly but while doing the same i ended up with below
> error
>
> i have a table DataModel() class through which i have defined the table as
> ORM
> datamodel = DataModel()
> ....
> datamodel.using(keyspace="tb1").save()
>
> TypeError: using_setter() got an unexpected keyword argument 'keyspace'
>
>
> After looking at the source i found that using() only takes connection and not keyspace as parameter.
>
> What is the alternative to achieve this?
>
> Please correct me if i am wrong.
> Thanks
>
>
> -Bimal
>
>
--
Alan Boudreault
e. alan.boudreault@datastax.com
w. www.datastax.com