Skip to content

Fix CSV import crash on malformed quoted fields - #36443

Merged
yan-3005 merged 4 commits into
mainfrom
seer/fix/entity-csv-unchecked-io-exception
Nov 5, 2026
Merged

yan-3005 merged 4 commits into
mainfrom
seer/fix/entity-csv-unchecked-io-exception

Conversation

@sentry

@sentry sentry Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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. Both EntityCsv.parse overloads only caught IOException, so the error escaped:

  • sync import endpoints returned HTTP 500 (UNHANDLED_SERVER_EXCEPTION);
  • importAsync jobs ended FAILED with the raw org.apache.commons.csv.CSVException text and logged an ERROR (the Sentry issue below).

What changed

  • Both parse overloads catch UncheckedIOException and report the cause as PARSER_FAILURE, so the import returns ABORTED.
  • parse(csv, true) now returns null on a parser failure, like parse(csv). It used to return an empty list, so importCsv(records) skipped its null guard and hit records.get(0): recursive database / schema / service imports still returned 500 with only the catch added.
  • The abort reason is now written for the person fixing the file. New CsvParseErrorMessage turns 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 to importCsv(records, ...), which already handles null. Nothing in the UI, ingestion or ITs matches on the old message text.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • Sync import, recursive sync import and importAsync of a CSV with a character after a closing quote return ABORTED with the line and the fix.
  • An unclosed quote reports the line the value starts on.

Unit tests

  • I added unit tests for the new/changed logic.
  • EntityCsvTest (72) — includes test_importMalformedCsvAbortsWithParserFailure and test_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, GlossaryResourceIT and ColumnCsvImportIT pass on MySQL + Elasticsearch. CsvAsyncJobResourceIT export-result downloads 404 the same way on clean main (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)

Before: main returns HTTP 500 and a FAILED job

After: the import aborts and names the line and the fix

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:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

Fixes COLLATE-BACKEND-DS

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@sentry
sentry Bot requested a review from a team as a code owner October 28, 2026 11:11
@sentry
sentry Bot requested a review from yan-3005 October 28, 2026 11:11
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@yan-3005 yan-3005 added To release Will cherry-pick this PR into the release branch 2.1 2.0 Needs to ship in a 2.0.x release (manual backport) labels Nov 4, 2026
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 yan-3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, GlossaryResourceIT and ColumnCsvImportIT pass on MySQL + ES.
  • CsvAsyncJobResourceIT export-result 404s fail the same way on clean main (5 of 16 there, 6 of 16 here, different tests each run), so they are not from this change.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@yan-3005
yan-3005 enabled auto-merge (squash) November 5, 2026 15:05
@yan-3005 yan-3005 added the safe to test Add this label to run secure Github workflows on PRs label Nov 5, 2026
@yan-3005
yan-3005 disabled auto-merge November 5, 2026 15:22
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.
@yan-3005
yan-3005 enabled auto-merge (squash) November 5, 2026 15:27
@yan-3005
yan-3005 merged commit d44ad6e into main Nov 5, 2026
63 of 64 checks passed
@yan-3005
yan-3005 deleted the seer/fix/entity-csv-unchecked-io-exception branch November 5, 2026 15:31
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

gh-bot-collate Bot commented Nov 5, 2026

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

yan-3005 added a commit that referenced this pull request Nov 6, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 Needs to ship in a 2.0.x release (manual backport) 2.1 safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant