Details
Description
While inserting a new fresh document using python sdk "couchbase.n1ql.N1QLError" is raised cause: Duplicate Key <key>', u'code': 12009
PLEASE NOTE: The document is getting created properly in the bucket even after the exception.
Another observation is that sometimes this exception is not coming and <couchbase.n1ql.N1QLRequest object at 0x1083ce250> is returned properly.
Step to reproduce:
1. Load a fresh bucket: default
2. Using python sdk try to insert few documents:
from couchbase.bucket import Bucket
from couchbase.n1ql import N1QLQuery
cb = Bucket('couchbase://10.142.160.101//default',username="Administrator", password="password")
cb.n1ql_query('INSERT INTO `default` (KEY, VALUE) VALUES ("4odwalla-juice1",
)').execute()
cb.n1ql_query('INSERT INTO `default` (KEY, VALUE) VALUES ("odwalla-juice",
{ "productId": "odwalla-juice1"})').execute()
cb.n1ql_query('INSERT INTO `default` (KEY, VALUE) VALUES ("abc",
{ "productId": "odwalla-juice1"})').execute()
I printed the statements coming in to n1ql and ran the above interactive python commands. It looks like each statement is being run twice. This is why you get the DML error
_time=2017-06-13T12:01:42.906-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice1",{ "productId": "odwalla-juice1"}) ---------------------
_time=2017-06-13T12:01:42.906-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice1",{ "productId": "odwalla-juice1"}) ---------------------
_time=2017-06-13T12:01:42.911-07:00 _level=ERROR _msg=Failed to perform insert on key 4odwalla-juice1 for Keyspace mybucket Error Duplicate Key 4odwalla-juice1
_time=2017-06-13T12:02:15.001-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("new_4odwalla-juice1",{ "productId": "new_odwalla-juice1"}) ---------------------
_time=2017-06-13T12:02:15.001-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("new_4odwalla-juice1",{ "productId": "new_odwalla-juice1"}) ---------------------
_time=2017-06-13T12:02:15.006-07:00 _level=ERROR _msg=Failed to perform insert on key new_4odwalla-juice1 for Keyspace mybucket Error Duplicate Key new_4odwalla-juice1
2017-06-13T12:02:17.002-07:00 [Info] connected with 1 indexers
2017-06-13T12:05:17.002-07:00 [Info] client load stats {}
_time=2017-06-13T12:05:31.620-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice2",{ "productId": "odwalla-juice1"}) ---------------------
_time=2017-06-13T12:05:31.620-07:00 _level=INFO _msg=
------------ This is the input statement :: INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice2",{ "productId": "odwalla-juice1"}) ---------------------
_time=2017-06-13T12:05:31.626-07:00 _level=ERROR _msg=Failed to perform insert on key 4odwalla-juice2 for Keyspace mybucket Error Duplicate Key 4odwalla-juice2
I ran the following
>>> cb.n1ql_query('INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice1",{ "productId": "odwalla-juice1"})').execute()
>>> cb.n1ql_query('INSERT INTO `mybucket` (KEY, VALUE) VALUES ("new_4odwalla-juice1",{ "productId": "new_odwalla-juice1"})').execute()
>>> cb.n1ql_query('INSERT INTO `mybucket` (KEY, VALUE) VALUES ("4odwalla-juice2",{ "productId": "odwalla-juice1"})').execute()