Fix CMR validation when pyQuARC is used as a library - #368
Open
slesaad wants to merge 1 commit into
Open
Conversation
The CMR validation feature added in v1.3.0 breaks every concept-id validation when pyQuARC is imported as a package (e.g. by QuARC's Lambda): 1. _validate_with_cmr() references CONTENT_TYPE_MAP, but the constant is only imported in the __name__ == "__main__" branch, so library usage raises: NameError: name 'CONTENT_TYPE_MAP' is not defined 2. Once that is fixed, cmr_response.json() raises JSONDecodeError for every collection that passes CMR validation, because CMR's ingest validate endpoint returns HTTP 200 with an empty body on success. Import CONTENT_TYPE_MAP in the package branch and parse the CMR response defensively, treating a non-JSON body as no errors/warnings. This also drops the duplicated .json() call. Verified against live CMR in a python3.9 Amazon Linux 2 container: ARC(input_concept_ids=["C1214470488-ASF"], metadata_format="echo-c") .validate() now returns full results with cmr_validation populated; tests pass (27 passed).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CMR validation feature added in v1.3.0 (#364) breaks every concept-id validation when pyQuARC is imported as a package — which is how QuARC's Lambda uses it. The QuARC staging API currently returns HTTP 500 for all concept-id requests because of this.
Two separate failures:
_validate_with_cmr()referencesCONTENT_TYPE_MAP, but that constant is only imported in theif __name__ == "__main__"branch ofmain.py. Library usage raises:With that fixed,
cmr_response.json()raisesJSONDecodeErrorfor every collection that passes CMR validation, because CMR's ingest validate endpoint returns HTTP 200 with an empty body on success (it only returns a JSON body when there are errors).Fix
CONTENT_TYPE_MAPin the package-import branch..json()call.Verification
Ran in a python3.9 Amazon Linux 2 container (matching the QuARC Lambda runtime) against live CMR:
Before the fix, the same call raises the
NameErrorabove. Full test suite: 27 passed.🤖 Generated with Claude Code