CouchDB
  1. CouchDB
  2. COUCHDB-605

_update handler doesn't conflict for existing document

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 0.10
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Ubuntu Karmic, in particular it's CouchDB version 0.10.0-0ubuntu3

    • Skill Level:
      Regular Contributors Level (Easy to Medium)

      Description

      design doc:
      "updates": {
      "hello": "function(doc, req)

      { doc.value = 100500; return [doc, 'foo bar']; }

      "
      }

      $ curl X PUT --data-binary @ http://localhost:5984/shkaf/client:foo << EOF
      >

      {"_id":"client:foo"}

      > EOF

      {"ok":true,"id":"client:foo","rev":"1-967a00dff5e02add41819138abb3284d"}

      $ curl X PUT --data-binary @ http://localhost:5984/shkaf/_design/client/_update/hello/client:foo?A=B << EOF
      >

      {"_id": "client:foo"}

      > EOF
      foo bar

      And it really updated the document.

      What i expected here is error: conflict because document with such _id already existed and i didn't provide _rev to _update handler.

        Activity

        Hide
        Benjamin Young added a comment -

        I see this as part of the benefit/usefulness of _update--that you can, as needed, ignore the MVCC pattern and update a doc regardless of matching _rev's. However, it should be possible to implement this by comparing a "rev" query param to the doc._rev if an existing ID is used. Sadly, (due to issue COUCHDB-648) it's not possible to send 409 Conflict error "by hand" (or any other developer chosen status code).

        Basically, _update handlers seem to need a bit more love before they'll be completely useful for stand-along apps or APIs built on top of CouchDB.

        Show
        Benjamin Young added a comment - I see this as part of the benefit/usefulness of _update--that you can, as needed, ignore the MVCC pattern and update a doc regardless of matching _rev's. However, it should be possible to implement this by comparing a "rev" query param to the doc._rev if an existing ID is used. Sadly, (due to issue COUCHDB-648 ) it's not possible to send 409 Conflict error "by hand" (or any other developer chosen status code). Basically, _update handlers seem to need a bit more love before they'll be completely useful for stand-along apps or APIs built on top of CouchDB.
        Hide
        Robert Newson added a comment -

        _update handlers do not allow you to ignore MVCC, the update can still fail with a real 409 if the doc is updated concurrently. All it's doing is giving you the current _rev value, but it's not performing any locking (there are no read or write locks in couchdb) so a successful update between the start of the update function and its return will cause the update handler to fail with 409.

        Show
        Robert Newson added a comment - _update handlers do not allow you to ignore MVCC, the update can still fail with a real 409 if the doc is updated concurrently. All it's doing is giving you the current _rev value, but it's not performing any locking (there are no read or write locks in couchdb) so a successful update between the start of the update function and its return will cause the update handler to fail with 409.

          People

          • Assignee:
            Chris Anderson
            Reporter:
            Sergey Shepelev
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development