Skip to content

Raise MissingDataError on malformed LOINC row instead of returning it - #1833

Open
Rdag15 wants to merge 1 commit into
cdisc-org:mainfrom
Rdag15:fix/loinc-terms-factory-raises
Open

Raise MissingDataError on malformed LOINC row instead of returning it#1833
Rdag15 wants to merge 1 commit into
cdisc-org:mainfrom
Rdag15:fix/loinc-terms-factory-raises

Conversation

@Rdag15

@Rdag15 Rdag15 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

LoincTermsFactory.install_terms returns a MissingDataError when a Loinc.csv data row has fewer than 9 fields, instead of raising it:

if len(values) < 9:
    return MissingDataError(message="Loinc term found without required fields provided")

So the caller (get_term_dictionary) stores the exception instance in place of the ExternalDictionary and caches it; a later code in term_dictionary check then fails with an opaque TypeError: argument of type 'MissingDataError' is not iterable, far from the actual cause (a malformed dictionary file — e.g. a truncated row or a trailing blank line).

Fix: raise it instead of returning it — consistent with the missing-file branch a few lines above in the same method, which already raises the same exception. Added a test (the short-row path had no coverage).

…ng it

install_terms did `return MissingDataError(...)` when a Loinc.csv data row had
fewer than 9 fields, so callers received the exception instance in place of an
ExternalDictionary and cached it; a later `code in term_dictionary` check then
raised an opaque TypeError far from the cause. The same method already raises
this exception for the missing-file case. Raise it here too.
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