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

Avoid creation of document if deleting attachment on non-existent doc #486

Merged

Conversation

jiangphcn
Copy link
Contributor

Overview

Prior to the change in this PR, one new document was unexpectedly created after a request is issued to delete attachment on non-existent document. This PR is aimed to address this to return 404 (Not Found) instead of creating new document.

Testing recommendations

The newly introduced test case should_return_404_for_delete_att_on_notadoc covers the steps to test the change in this PR. In addition, two additional test cases should_return_409_for_del_att_without_rev and should_return_200_for_del_att_with_rev are introduced to make sure that there is no regression.

======================== EUnit ========================
chttpd db tests
  chttpd_db_test:71: should_return_ok_true_on_bulk_update...[0.107 s] ok
  chttpd_db_test:86: should_accept_live_as_an_alias_for_continuous...[0.054 s] ok
  chttpd_db_test:107: should_return_404_for_delete_att_on_notadoc...[0.005 s] ok
  chttpd_db_test:129: should_return_409_for_del_att_without_rev...[0.052 s] ok
  chttpd_db_test:155: should_return_200_for_del_att_with_rev...[0.078 s] ok
[os_mon] cpu supervisor port (cpu_sup): Erlang has closed
  [done in 1.563 s]

JIRA issue number

COUCHDB-3362

Related Pull Requests

N/A

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • [] Documentation reflects the changes;
  • I will not forget to update rebar.config.script
    with the correct commit hash once this PR get merged.

No documentation change since the changed behavior is aligned with statement in document http:https://docs.couchdb.org/en/2.0.0/api/document/attachments.html#delete--db-docid-attname

  - Check existence of document before deleting its attachment
  - if document doesn’t exist, return 404 instead of creating new
    document

Fixes COUCHDB-3362/FB 85549
Copy link
Contributor

@iilyak iilyak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests pass locally

    Running test function(s):
      chttpd_db_doc_size_tests:all_test_/0
      chttpd_db_test:all_test_/0
======================== EUnit ========================
chttpd db tests
  chttpd_db_test:71: should_return_ok_true_on_bulk_update...[0.091 s] ok
  chttpd_db_test:86: should_accept_live_as_an_alias_for_continuous...[0.032 s] ok
  chttpd_db_test:107: should_return_404_for_delete_att_on_notadoc...[0.016 s] ok
  chttpd_db_test:129: should_return_409_for_del_att_without_rev...[0.027 s] ok
  chttpd_db_test:155: should_return_200_for_del_att_with_rev...[0.038 s] ok
  [done in 0.808 s]
chttpd db max_document_size tests
  chttpd_db_doc_size_tests:72: post_single_doc...[0.002 s] ok
  chttpd_db_doc_size_tests:83: put_single_doc...[0.001 s] ok
  chttpd_db_doc_size_tests:100: bulk_doc...ok
  chttpd_db_doc_size_tests:128: put_post_doc_attach_inline...ok
  chttpd_db_doc_size_tests:149: put_multi_part_related...ok
  chttpd_db_doc_size_tests:172: post_multi_part_form...ok
  [done in 0.596 s]
=======================================================
  All 11 tests passed.

@iilyak iilyak merged commit 4aba3bc into apache:master Apr 24, 2017
@iilyak iilyak deleted the COUCHDB-3362-delete-att-on-nonexistdoc branch April 24, 2017 16:47
nickva pushed a commit to nickva/couchdb that referenced this pull request Sep 7, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants