Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-408

While inserting a new fresh document using python sdk "couchbase.n1ql.N1QLError" is raised cause: Duplicate Key <key>', u'code': 12009

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Test Blocker
    • Resolution: Fixed
    • 2.2.3, 2.2.4, 2.2.5
    • 2.2.6
    • library
    • None
    • couchbase==2.2.4
      CB Version = Enterprise Edition 5.0.0 build 2837

    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",

      { "productId": "odwalla-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()

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          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()
          

           

          isha Isha Kandaswamy added a comment - 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()  

          Mark Nunberg: Can you add the info you'd referred to earlier and/or triage this a bit further.  If it's with the client, let's move it to a PYCBC.

          ingenthr Matt Ingenthron added a comment - Mark Nunberg : Can you add the info you'd referred to earlier and/or triage this a bit further.  If it's with the client, let's move it to a PYCBC.

          This is the result of the client sending out a duplicate query. The duplicate query is due to a typo. It mostly slipped through our tests because we've only tested queries. A second query would indeed get sent out, but would be GC'd anyway and otherwise ignored (though it would cost us a socket connection).

          mnunberg Mark Nunberg (Inactive) added a comment - This is the result of the client sending out a duplicate query. The duplicate query is due to a typo. It mostly slipped through our tests because we've only tested queries. A second query would indeed get sent out, but would be GC'd anyway and otherwise ignored (though it would cost us a socket connection).

          Sorry for the delay on this one!

          mnunberg Mark Nunberg (Inactive) added a comment - Sorry for the delay on this one!

          Where can i find the python sdk build 2.2.6 to verify this defect?

          ritesh.agarwal Ritesh Agarwal added a comment - Where can i find the python sdk build 2.2.6 to verify this defect?

          People

            mnunberg Mark Nunberg (Inactive)
            ritesh.agarwal Ritesh Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty