You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/09/27 15:14:57 UTC

[GitHub] ricellis opened a new issue #1628: Possible to write `_local` docs into the revisioned doc tree

ricellis opened a new issue #1628: Possible to write `_local` docs into the revisioned doc tree
URL: https://github.com/apache/couchdb/issues/1628
 
 
   <!--- Provide a general summary of the issue in the Title above -->
   
   ## Expected Behavior
   <!--- If you're describing a bug, tell us what should happen -->
   <!--- If you're suggesting a change/improvement, tell us how it should work -->
   
   Expect `_local` prefixed docs not to end up in the normal versioned doc tree.
   
   ## Current Behavior
   <!--- If describing a bug, tell us what happens instead of the expected behavior -->
   <!--- If suggesting a change/improvement, explain the difference from current behavior -->
   
   If using `_bulk_docs` and `"new_edits":false` it is possible to write a `_local` prefixed doc into the normal doc tree. Once it is there it is not possible to read or delete the document via normal means. The document is included in `_changes` `_all_docs` and replications. It also plays havoc with the dashboard where it is visible in the document list, but the document cannot be deleted nor can the content be retrieved.
   
   ## Possible Solution
   <!--- Not obligatory, but suggest a fix/reason for the bug, -->
   <!--- or ideas how to implement the addition or change -->
   
   I wasn't able to reproduce when using the default `"new_edits":true`, so perhaps whatever checks are made for `_local` docs there could be extended to the `"new_edits": false case.
   
   ## Steps to Reproduce (for bugs)
   <!--- Provide a link to a live example, or an unambiguous set of steps to -->
   <!--- reproduce this bug. Include code to reproduce, if relevant -->
   1. Create DB
       `curl -XPUT http://localhost:5984/test` -->
       `{"ok":true}`
   1. Write `_local/test` doc with a `_rev`
       `curl -XPOST -HContent-Type:application/json http://localhost:5984/test/_bulk_docs -d '{"new_edits":false,"docs":[{"_id":"_local/test","_rev":"1-abcdef","hello":"world"}]}'` -->
       `[]`
   1. Try to `GET` the `_local/test` doc
       `curl http://localhost:5984/test/_local/test` -->
      `{"error":"not_found","reason":"missing"}`
   1. Try to `GET` the `_local/test` doc via `_all_docs`
       `curl 'http://localhost:5984/test/_all_docs?key="_local/test"&include_docs=true'` -->
       `{"total_rows":1,"offset":0,"rows":[
   {"id":"_local/test","key":"_local/test","value":{"rev":"1-abcdef"},"doc":{"_id":"_local/test","_rev":"1-abcdef","hello":"world"}}
   ]}`
   1. Try to delete the `_local/test` doc
       `curl -XDELETE http://localhost:5984/test/_local/test` -->
       `{"error":"not_found","reason":"missing"}`
   1. Try to delete via `_bulk_docs` and `_deleted` flag
       `curl -XPOST -HContent-Type:application/json http://localhost:5984/test/_bulk_docs -d '{"docs":[{"_id":"_local/test","_rev":"1-abcdef","_deleted":true}]}` -->
       `[{"id":"_local/test","error":"unknown_error","reason":"undefined"}]`
   1. Try to delete via `_bulk_docs` and `_deleted` flag with `"new_edits":false`
       `curl -XPOST -HContent-Type:application/json http://localhost:5984/test/_bulk_docs -d '{"new_edits":false, "docs":[{"_id":"_local/test","_rev":"1-abcdef","_deleted":true}]}` -->
       `[{"id":"_local/test","error":"unknown_error","reason":"undefined"}]`
   
   ## Context
   <!--- How has this issue affected you? What are you trying to accomplish? -->
   <!--- Providing context helps us come up with a solution that is most useful in the real world -->
   
   A user wrote a document with a [`_local` prefixed `_id` and a `_rev` into a local datastore in our sync-android library](https://github.com/cloudant/sync-android/issues/589). Once that was in the local store it made it into our replication path and was written to the server via `_bulk_docs` with `"new_edits":false` (as all docs that need replicating do).
   
   Clearly we could make some improvements to sync-android in terms of documentation or preventing the insertion of a doc with `_local` prefix and a rev into its local database, but I think there is a genuine issue that needs resolving in CouchDB as well in that the server side `_bulk_docs` API has similar problems in allowing a `_local` prefixed doc to be written into the wrong part of a database, especially because it creates a document that is not removable via the normal HTTP APIs.
   
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: 2.2.0 (I've also reproduced on 1.7.2)
   * Browser Name and version: Firefox 60.2.1 (for dashboard)
   * Operating System and version (desktop or mobile): Docker `couchdb` image (but reproducible in other envs)
   * Link to your project: https://github.com/cloudant/sync-android
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services