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 2021/07/14 19:41:46 UTC
[GitHub] [couchdb] noahshaw11 opened a new pull request #3667: Fix response code for nonexistent attachment
noahshaw11 opened a new pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667
## Overview
Currently, a DELETE request for a non existent attachment responds with a 200 OK even if the attachment is missing. This PR changes the response code for nonexistent attachments to a 404 NOT FOUND `{"error":"not_found","reason":"Document is missing attachment"}`
## Testing recommendations
```
% curl -X PUT http://localhost:15984/demo/38 -H 'Authorization: Basic YWRtOnBhc3M=' -d '{"name": "whatever"}'
{"ok":true,"id":"38","rev":"1-a0f595984a7c4cf1dafc4cf4c04081d6"}
% curl -X DELETE 'http://adm:pass@localhost:15984/demo/38/notexisting.txt?rev=1-a0f595984a7c4cf1dafc4cf4c04081d6'
{"error":"not_found","reason":"Document is missing attachment"}
```
## Related Issues or Pull Requests
Deleting not existing attachment responds 200 instead of 404: https://github.com/apache/couchdb/issues/2146
## Checklist
- [ ] Code is written and works correctly
- [ ] Changes are covered by tests
- [ ] Any new configurable parameters are documented in `rel/overlay/etc/default.ini`
- [ ] A PR for documentation changes has been made in https://github.com/apache/couchdb-documentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r669983596
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1828,18 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
)
),
+ case Method of
+ 'DELETE' ->
+ case get_attachment(Req, Db, DocId, FileName) of
Review comment:
Looks much better, I think!
We can improve it a bit by moving it under the `case Method of 'DELETE' of ` clause since we already have a clause for DELETE and we're not doing anything but returning `[]` so instead we could check for existence there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] noahshaw11 commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
noahshaw11 commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r670671799
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1819,21 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
)
),
+ % Check if attachment exists
+ #doc_query_args{
+ rev=Rev,
+ options=Options
+ } = parse_doc_query(Req),
+ #doc{
+ atts=Atts
+ } = Doc = couch_doc_open(Db, DocId, Rev, Options),
+ case [A || A <- Atts, couch_att:fetch(name, A) == FileName] of
+ [] ->
+ throw({not_found, "Document is missing attachment"});
Review comment:
Fixed in https://github.com/apache/couchdb/pull/3667/commits/7190c7eb72ba4bdcb6112efa9aabe2436e094528.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva commented on pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva commented on pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#issuecomment-881924037
Merged. This should apply to 3.x with some minor changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] noahshaw11 commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
noahshaw11 commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r671554426
##########
File path: test/elixir/test/attachments_test.exs
##########
@@ -109,6 +109,11 @@ defmodule AttachmentsTest do
resp = Couch.delete("/#{db_name}/bin_doc/foo.txt", query: %{w: 3})
assert resp.status_code == 409
+
+ resp = Couch.delete("/#{db_name}/bin_doc/notexisting.txt?rev=1-a0f595984a7c4cf1dafc4cf4c04081d6")
+ assert resp.status_code == 404
+ assert resp.body["error"] == "not_found"
Review comment:
Fixed in https://github.com/apache/couchdb/pull/3667/commits/0b62354ba5c10ec5a891e1525b828e76939cb2c9 and https://github.com/apache/couchdb/pull/3667/commits/c2bc260de0aafc5c8d16116899641c62559c6747.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r669983596
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1828,18 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
)
),
+ case Method of
+ 'DELETE' ->
+ case get_attachment(Req, Db, DocId, FileName) of
Review comment:
Looks much better, I think!
We can improve it a bit by moving it under the `case Method of 'DELETE' -> ... ` clause since we already have a clause for DELETE and we're not doing anything but returning `[]` so instead we could check for existence there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r669922418
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1819,21 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
)
),
+ % Check if attachment exists
+ #doc_query_args{
+ rev=Rev,
+ options=Options
+ } = parse_doc_query(Req),
+ #doc{
+ atts=Atts
+ } = Doc = couch_doc_open(Db, DocId, Rev, Options),
+ case [A || A <- Atts, couch_att:fetch(name, A) == FileName] of
+ [] ->
+ throw({not_found, "Document is missing attachment"});
Review comment:
This should be for `DELETE` only not `PUT`?
I saw the logic for opening the named attachment is similar to the code in `GET` handler, perhaps we can re-use it as `get_attachment(Req, Db, DocID, Rev, FileName) -> {ok, Att} | {error, missing}` which both GET and DELETE can re-use?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r671515753
##########
File path: test/elixir/test/attachments_test.exs
##########
@@ -109,6 +109,11 @@ defmodule AttachmentsTest do
resp = Couch.delete("/#{db_name}/bin_doc/foo.txt", query: %{w: 3})
assert resp.status_code == 409
+
+ resp = Couch.delete("/#{db_name}/bin_doc/notexisting.txt?rev=1-a0f595984a7c4cf1dafc4cf4c04081d6")
+ assert resp.status_code == 404
+ assert resp.body["error"] == "not_found"
Review comment:
I wonder why we don't see the "Document is missing attachment" error reason propagate here...
Also, we probably shouldn't hardcode the revision number but get the current on from the document (`rev` variable should have?).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] nickva merged pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
nickva merged pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] noahshaw11 commented on a change in pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
noahshaw11 commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r670672048
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1828,18 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
)
),
+ case Method of
+ 'DELETE' ->
+ case get_attachment(Req, Db, DocId, FileName) of
Review comment:
Moved in https://github.com/apache/couchdb/pull/3667/commits/222f1c21573ee3067ddc63df437f8a591d8c4300.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [couchdb] jjrodrig commented on pull request #3667: Fix response code for nonexistent attachment
Posted by GitBox <gi...@apache.org>.
jjrodrig commented on pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#issuecomment-880462753
Hi @noahshaw11,
Please, could you extend the test case for attachment deletion here?
https://github.com/apache/couchdb/blob/main/test/elixir/test/attachments_test.exs#L102
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org