Repository navigation
Fix CSV import crash on malformed quoted fields - #36443
Conversation
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
parse(csv, true) returned an empty list after documenting a parser failure, so importCsv(records) skipped its null guard and hit records.get(0), turning the parser error into a 500 on recursive database, schema and service imports. Return null like parse(csv) so the import aborts with PARSER_FAILURE, and share the failure reporting between both overloads.
yan-3005
left a comment
There was a problem hiding this comment.
Took this over and verified it on a live server (MySQL + Elasticsearch, dryRun=true, a row with a stray character after a closing quote).
The original patch fixed sync and async glossary import, but recursive database/schema/service import still returned 500: parse(csv, true) returned an empty list after a parser failure, so importCsv(records) skipped its null guard and hit records.get(0). d8f873f returns null like parse(csv) and shares the failure reporting between the overloads. Also merged main in.
| Case | main | PR as opened | now |
|---|---|---|---|
| Glossary sync import | 500 CSVException |
200 aborted, #PARSER_FAILURE |
200 aborted, #PARSER_FAILURE |
Database sync import, recursive=true |
500 CSVException |
500 Index 0 out of bounds |
200 aborted, #PARSER_FAILURE |
Glossary importAsync |
job FAILED | COMPLETED, result aborted | COMPLETED, result aborted |
Tests:
EntityCsvTest: 72 run, 0 failures. The new recursive test fails without the fix (expected: <null> but was: <[]>).- CSV/import methods of
DatabaseResourceIT,DatabaseSchemaResourceIT,DatabaseServiceResourceIT,GlossaryResourceITandColumnCsvImportITpass on MySQL + ES. CsvAsyncJobResourceITexport-result 404s fail the same way on cleanmain(5 of 16 there, 6 of 16 here, different tests each run), so they are not from this change.
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
The abort reason echoed the Commons CSV lexer text ("Invalid character
between encapsulated token and delimiter ... position: 140"), with a
file-wide character offset and a "CSV filed" typo. Translate the two
lexer errors users hit (characters after a closing quote, unclosed
quote) into the line number and the fix, and drop the character offset
from any other parser message.
|
🤖 Backport to |
|
🤖 Backport to |
Catch the UncheckedIOException Commons CSV raises for malformed quoted fields in both EntityCsv.parse overloads and report it as PARSER_FAILURE, return null from the recursive overload so recursive imports abort cleanly instead of failing with a 500, and word the abort reason as the line and the fix (characters after a closing quote, unclosed quote) instead of the raw lexer message. (cherry picked from commit d44ad6e) Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
Describe your changes:
Importing a CSV with a malformed quoted field (a stray character after a closing quote, or a quote that is never closed) failed with a server error instead of a clean import result.
Why it happened
Commons CSV 1.12 wraps lexer errors raised while iterating records in
UncheckedIOException. BothEntityCsv.parseoverloads only caughtIOException, so the error escaped:UNHANDLED_SERVER_EXCEPTION);importAsyncjobs ended FAILED with the raworg.apache.commons.csv.CSVExceptiontext and logged an ERROR (the Sentry issue below).What changed
parseoverloads catchUncheckedIOExceptionand report the cause asPARSER_FAILURE, so the import returnsABORTED.parse(csv, true)now returnsnullon a parser failure, likeparse(csv). It used to return an empty list, soimportCsv(records)skipped its null guard and hitrecords.get(0): recursive database / schema / service imports still returned 500 with only the catch added.CsvParseErrorMessageturns the two lexer errors users hit into the line and the fix, drops the file-wide character offset from any other parser message, and fixes the "CSV filed" typo:line 2 has characters after the closing quote of a quoted value. A closing quote must be followed by a comma or the end of the line; to put a quote inside a value, write it twice ("").line 3 starts a quoted value that is never closed. Add the missing closing quote.The whole file is still rejected rather than one row: after a syntax error the parser cannot tell where the bad row ends (it returns the next record with the bad value blanked, and an unclosed quote swallows the rest of the file), so skipping one row could import corrupted values.
Blast radius
Only malformed CSVs behave differently. The
parse(csv, true)null return reaches its four callers (DatabaseRepository,DatabaseSchemaRepository,DatabaseServiceRepository,DriveServiceRepository), which all pass it toimportCsv(records, ...), which already handlesnull. Nothing in the UI, ingestion or ITs matches on the old message text.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
importAsyncof a CSV with a character after a closing quote returnABORTEDwith the line and the fix.Unit tests
EntityCsvTest(72) — includestest_importMalformedCsvAbortsWithParserFailureandtest_recursiveImportOfMalformedCsvAbortsWithParserFailure; the recursive test fails without the fix (expected: <null> but was: <[]>).CsvParseErrorMessageTest(3) — parses with the real library, so a Commons CSV upgrade that rewords its errors fails here.CsvParseTest,CsvUtilTest— 88 run, 0 failures in total.Backend integration tests
CSV/import methods of
DatabaseResourceIT,DatabaseSchemaResourceIT,DatabaseServiceResourceIT,GlossaryResourceITandColumnCsvImportITpass on MySQL + Elasticsearch.CsvAsyncJobResourceITexport-result downloads 404 the same way on cleanmain(5 of 16 there, 6 of 16 here, a different set each run), so those failures are not from this change.Live server (MySQL + Elasticsearch,
dryRun=true)Ingestion integration tests
N/A
Playwright (UI) tests
N/A — backend-only change.
UI screen recording:
Not applicable — backend-only CSV parsing fix with no UI changes.
Checklist:
Fixes <issue-number>: <short explanation>REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge.Fixes COLLATE-BACKEND-DS
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry. You can adjust this setting at any time.