Hi, I’m a bit stuck and I’d like some help. I have get an error when executing a query at a close interval:
File "/Users/myUser/project/api/venv/lib/python3.8/site-packages/couchbase_core/n1ql.py", line 415, in _submit_query
return self._parent._n1ql_query(self._params.encoded,
couchbase.exceptions.ObjectThreadException: <Couldn't lock. If LOCKMODE_WAIT was passed, then this means that something has gone wrong internally. Otherwise, this means you are using the Connection object from multiple threads. This is not allowed (without an explicit lockmode=LOCKMODE_WAIT constructor argument, C Source=(src/oputil.c,668)>
print(cluster.lockmode)
returns “1”, which is LOCKMODE_EXC, the default value
I tried using from couchbase.options import LockMode lockmode=LockMode.WAIT
but it also returns “1”.
I’m a Junior so maybe this issue is simple to solve since I couldn’t find anything on it. If you could just point me in the right direction as to how I should fix this issue it would be great.
Hi, it should be lock_mode in ClusterOptions. Interesting that lockmode makes it through (the options and **kwargs are merged, using the same keywords). Will inspect that piece of code.
I have tried setting it with multiple versions of python couch sdk (3.0.2, 3.0.3, 3.0.4, 3.0.5) by passing lockmode=2 in either Cluster or ClusterOptions. But none of those working. I see there is an open issue to resolve this, would like to know if any work arounds f0r our flask based application until we get new sdk with this fix available. Thanks in advance.
This actually is an issue with the “bucket” not having the correct lockmode…
When you use the cluster object to get a bucket cluster.bucket what happens is that it does not pass down the LockMode set on the cluster object. So the only work around is calling the underlying cluster object in the cluster and calling the open_bucket method and passing in the bucket lockmode.
IE
bucket = cluster._cluster.open_bucket(bucket_name, lockmode=2)
The bucket object will now have lockmode set.
Couchbase needs to fix in the SDK when using the abstraction layer of the cluster when getting a bucket ie .Bucket to pass back the cluster settings to the bucket settings, or at least allow the user to pass down some settings when creating the bucket.
cluster._cluster.open_bucket is not available any more in Python SDK 3.x, there seems no workaround for this, the lockmode cannot be carried over from Cluster.
I have to take a look at my code but I believe that the reason why my lock mode worked is because my app only used N1QL queries, so I only used cluster.query(A_Query). Sorry for my misleading answers, LockMode for the bucket probably doesn’t work with the “solution” I mentioned above.
thank you @mplachter, you’re correct.
the open_bucket does exist and it’s working!!!
self._bucket = self._cluster._cluster.open_bucket(self._bucket_name, lockmode=LOCKMODE_WAIT) #work around to set lockmode
self._collection = self._bucket.default_collection()