You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "Mike Wallace (JIRA)" <ji...@apache.org> on 2015/08/13 17:34:46 UTC

[jira] [Closed] (COUCHDB-2774) COPY request creates a target document with a different revision hash

     [ https://issues.apache.org/jira/browse/COUCHDB-2774?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Wallace closed COUCHDB-2774.
---------------------------------
       Resolution: Not A Problem
    Fix Version/s: 2.0.0

Already fixed on master.

> COPY request creates a target document with a different revision hash
> ---------------------------------------------------------------------
>
>                 Key: COUCHDB-2774
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2774
>             Project: CouchDB
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: Database Core
>            Reporter: Mike Wallace
>             Fix For: 2.0.0
>
>
> HTTP COPY requests create an identical copy of the source document. As the body of the target is unchanged the revision hash should also be unchanged, however that is not currently the case:
> $ URL=http://localhost:15984
> $ curl -X PUT $URL/doge
> {"ok":true}
> $ curl -X PUT $URL/doge/shibe1 -d '{"such doge":"very doc"}'
> {"ok":true,"id":"shibe1","rev":"1-6429670183877c94fed5cc7996cd880a"}
> $ curl -X COPY $URL/doge/shibe1 -H 'Destination: shibe2'
> {"ok":true,"ok":true,"id":"shibe2","rev":"1-c73d863c32ec87653923959eae56920b"}
> $ curl -X GET $URL/doge/shibe2
> {"_id":"shibe2","_rev":"1-c73d863c32ec87653923959eae56920b","such doge":"very doc"}
> The reason for the difference is because the document opened in the copy handler has a binary body [1]. When the revision hash is generated on update the binary is passed into couch_db:new_revid/1 and hence the hash is different. If we change the binary body to an ejson body and save the doc then the revision hash is the same [2].
> There are two possible solutions. One is to add a clause to couch_db:new_revid/1 which converts any binary doc bodies to ejson [3], the alternative is to open the doc with the ejson_body option in the chttpd_db handler fun.
> I prefer the second approach, using ejson_body to open the doc in chttpd_db, since it is simpler and further up the stack, so less likely to have any unfortunate side-effects.
> Unless anyone comments to the contrary I'll PR the second option.
> [1] https://github.com/apache/couchdb-chttpd/blob/master/src/chttpd_db.erl#L774
> [2] https://gist.github.com/mikewallace1979/592b65b2e51ca5f9a1a7
> [3] https://github.com/apache/couchdb-couch/commit/2b44b8d6eb865e24e05866e7aa8dd57d076a01d6



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)