SD.upsert in sdk 3

Hi Team,

I am wondering if there has been change to subdocument.upsert in python sdk 3.x?
In 2.5 I am using below statement to update a document but looks like same is not working in 3.0.3.

cb_collection.mutate_in(docid, SD.upsert(key, str(value))
I am importing SD from:
import couchbase_core.subdocument as SD
and cb_collection is collection object that I got from bucket.default_collection() as per sdk 3.x

Error that I am getting after mutate_in operation gets executed on SD.upsert operation is:
couchbase.exceptions.InvalidArgumentException: <Expected tuple for spec, C Source=(src/oputil.c,784), OBJ=5>

Please help!

Yes, if you look at the type hints, it explicitly describes that you need to pass an Iterable of Specs instead of a variadic list - so you would now do this:

import couchbase.subdocument as SD
cb_collection.mutate_in(docid, [SD.upsert(key, str(value))])

Note that we have deprecated all use of couchbase_core for all end users, and you should use the equivalent packages in couchbase instead.

Apologies if this is not clear in the docs - there is a ticket to address this.

Thanks,

Ellis

Thank you @ellis.breen! That worked!

1 Like