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

CMR-9848: When submitting multiple associations, if one fails CMR returns a 400 but still makes the other associations #2198

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

jmaeng72
Copy link
Contributor

@jmaeng72 jmaeng72 commented Dec 11, 2024

Overview

What is the problem?

When some associations in POST request, fail, but some succeed. The response returns a 400 for association endpoints, but we want it to reflect the true state that some associations failed.

What is the Solution?

If a request with multiple associations returns with some successes and some failures, we will return a 207 MULT-STATUS instead, with each association having its own status of 200 or 400 based on success or failure.

Associations affected:

  • Tool
  • Service
  • Concept/Generic
  • Tag
  • Variable

New Expected Response Status Behavior:

  • 200 OK -- if all associations succeeded
  • 207 MULTI-STATUS -- if some associations succeeded and some failed due to user error
  • 400 BAD REQUEST -- if all associations failed due to user error

What areas of the application does this impact?

Search App

Checklist

  • I have updated/added unit and int tests that prove my fix is effective or that my feature works
  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors corrected
  • I have removed unnecessary/dead code and imports in files I have changed
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • refactored to reduce number of system state resets by updating fixtures (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

siwei xu and others added 28 commits June 5, 2024 10:22
@jmaeng72 jmaeng72 self-assigned this Dec 11, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 84.37500% with 15 lines in your changes missing coverage. Please review.

Project coverage is 58.27%. Comparing base (fe3fde2) to head (66cba06).

Files with missing lines Patch % Lines
search-app/src/cmr/search/api/tags.clj 61.11% 6 Missing and 1 partial ⚠️
...rch-app/src/cmr/search/api/generic_association.clj 81.25% 2 Missing and 1 partial ⚠️
...nt-test/src/cmr/system_int_test/utils/tag_util.clj 86.66% 0 Missing and 2 partials ⚠️
search-app/src/cmr/search/api/association.clj 93.75% 0 Missing and 1 partial ⚠️
...est/src/cmr/system_int_test/utils/service_util.clj 93.33% 0 Missing and 1 partial ⚠️
...t-test/src/cmr/system_int_test/utils/tool_util.clj 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2198      +/-   ##
==========================================
+ Coverage   58.23%   58.27%   +0.04%     
==========================================
  Files        1056     1056              
  Lines       71012    71075      +63     
  Branches     2023     2029       +6     
==========================================
+ Hits        41351    41417      +66     
+ Misses      27772    27763       -9     
- Partials     1889     1895       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

search-app/src/cmr/search/api/association.clj Show resolved Hide resolved
search-app/src/cmr/search/api/association.clj Outdated Show resolved Hide resolved
search-app/src/cmr/search/api/generic_association.clj Outdated Show resolved Hide resolved
search-app/src/cmr/search/api/generic_association.clj Outdated Show resolved Hide resolved
search-app/src/cmr/search/api/tags.clj Show resolved Hide resolved
search-app/src/cmr/search/api/tags.clj Show resolved Hide resolved
:headers {"Content-Type" mt/json}}))
(if (= 207 status-code)
{:status status-code
:body (json/generate-string (util/snake-case-data (cmr.search.api.association/add-individual-statuses data)))
Copy link
Contributor

Choose a reason for hiding this comment

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

cmr.search.api.association, you simplify by adding path to imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh my how did that get in there

Copy link
Contributor

Choose a reason for hiding this comment

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

if we were under different dictatorships I would say this should be fine for a one off, but alas the overlords must be appeased.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -98,3 +98,12 @@
:body
first
:tool-association)))

(defn add-individual-statuses
Copy link
Contributor

Choose a reason for hiding this comment

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

explain why your creating atoms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hoping maybe someone knew a better way to do this. But essentially I am taking a list of maps and need to add an item into each map and return the changed list of maps. I did not know how to do this without using atoms in clojure

Copy link
Contributor

Choose a reason for hiding this comment

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

We talked off line, I would suggest that you take the recommended code with a grain of salt and proceed as you see best. I prefer that you do not introduce an atom, but if the code mentioned does not work or causes a delay then roll it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated atom funcs to remove atom -- AI for the win this time

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.

4 participants