Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couch 412 error "missing_stub" on saving document with attachment which was previously uploaded as inline attachment #7

Open
tungj opened this issue Jan 18, 2012 · 1 comment

Comments

@tungj
Copy link

tungj commented Jan 18, 2012

If you save a document with an inline attachment, the changes from 1.26 lib/AnyEvent/CouchDB/Database.pm save_doc $_attachments subroutine delete the attachment 'data' property and replace it with length, revpos, and stub:true.

Since revpos is extracted with a regex, it's in string context. The next time you save the document, the revpos in the attachment stub is sent to the server as a string. Unfortunately, on couchdb 1.1.1, this causes an error 412 since CouchDB expects revpos to be a number, and gives a {"error":"missing_stub","reason":"id:test, name:test3.gif"} response.

e.g. with a document with a 'test3.gif' attachment uploaded at revpos 2, curl -X PUT localhost:5984/database/test -d '{"_id":"test", "_rev":"14-47afaef5d143f63a9f9104e90c1ce71a", "_attachments":{"test3.gif":{"revpos":"2","length":6,"stub":true}}}' fails, but curl -X PUT localhost:5984/database/test -d '{"_id":"test", "_rev":"14-47afaef5d143f63a9f9104e90c1ce71a", "_attachments":{"test3.gif":{"revpos":2,"length":6,"stub":true}}}' works.

One possible solution is to use revpos in a numeric context before saving so it'll be serialized as a number, the other solution is to just delete it before sending since CouchDB seems happy to accept {stub:true}.

Incidentally, CouchDB 1.1.1 adds an MD5 'digest' field to the returned stub; it can be left out when saving the document though as long as {stub:true} is present.

@mralexgray
Copy link

why hasn't this been fixed, it sucks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants