Skip to content

Fix CMR validation when pyQuARC is used as a library - #368

Open
slesaad wants to merge 1 commit into
masterfrom
fix/cmr-validation-library-usage
Open

Fix CMR validation when pyQuARC is used as a library#368
slesaad wants to merge 1 commit into
masterfrom
fix/cmr-validation-library-usage

Conversation

@slesaad

@slesaad slesaad commented Jul 28, 2026

Copy link
Copy Markdown
Member

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:

  1. _validate_with_cmr() references CONTENT_TYPE_MAP, but that constant is only imported in the if __name__ == "__main__" branch of main.py. Library usage raises:

    NameError: name 'CONTENT_TYPE_MAP' is not defined
    
  2. With that 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 (it only returns a JSON body when there are errors).

Fix

  • Import CONTENT_TYPE_MAP in the package-import branch.
  • Parse the CMR response defensively: a non-JSON/empty body is treated as no errors/warnings. This also drops the duplicated .json() call.

Verification

Ran in a python3.9 Amazon Linux 2 container (matching the QuARC Lambda runtime) against live CMR:

arc = ARC(input_concept_ids=["C1214470488-ASF"], metadata_format="echo-c",
          cmr_host="https://cmr.earthdata.nasa.gov")
results = arc.validate()
# concept_id: C1214470488-ASF, 85 checked fields,
# cmr_validation: {"errors": [], "warnings": []}, pyquarc_errors: []

Before the fix, the same call raises the NameError above. Full test suite: 27 passed.

🤖 Generated with Claude Code

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).
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.

1 participant