From c5093cae590c72d3dd36babda6d6f5178aa02db3 Mon Sep 17 00:00:00 2001 From: Slesa Adhikari Date: Tue, 28 Jul 2026 15:46:06 -0500 Subject: [PATCH] Fix CMR validation when pyQuARC is used as a library 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). --- pyQuARC/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pyQuARC/main.py b/pyQuARC/main.py index 361a4286..b486207c 100644 --- a/pyQuARC/main.py +++ b/pyQuARC/main.py @@ -19,7 +19,7 @@ from code.utils import get_concept_type, get_headers else: from .code.checker import Checker - from .code.constants import COLOR, ECHO10_C, SUPPORTED_FORMATS + from .code.constants import COLOR, ECHO10_C, SUPPORTED_FORMATS, CONTENT_TYPE_MAP from .code.downloader import Downloader from .code.utils import get_cmr_url, is_valid_cmr_url from .code.utils import get_concept_type, get_headers @@ -234,15 +234,20 @@ def validate(self): content = content.encode() cmr_response = self._validate_with_cmr(concept_id, content) + try: + cmr_validation = cmr_response.json() + except ValueError: + # CMR returns an empty body when validation succeeds + cmr_validation = {} validation_errors, pyquarc_errors = checker.run(content) self.errors.append( { "concept_id": concept_id, "errors": validation_errors, "cmr_validation": { - "errors": cmr_response.json().get("errors", []), + "errors": cmr_validation.get("errors", []), # TODO: show warnings - "warnings": cmr_response.json().get("warnings", []) + "warnings": cmr_validation.get("warnings", []) }, "pyquarc_errors": pyquarc_errors, }