Repository navigation
Do not corrupt XCom values that already parse as JSON in the bytea to JSONB migration (#71926) - #72886
Merged
vatsrahul1001 merged 2 commits intoSep 10, 2026
Conversation
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 54f4300)
… JSONB migration (#71926) * Substitute null for non-finite floats in the XCom bytea to JSONB migration The sanitizer in 0049 wrapped NaN/Infinity/-Infinity in unescaped double quotes, which is only valid at the top level of a JSON document. When the XCom value is a JSON string wrapping another JSON document every interior quote is backslash-escaped, so the injected quote closes the wrapping string and the bytea -> JSONB cast aborts. null needs no quoting, so it is correct at any nesting depth. Also moves the run of spaces after the delimiter inside group 1 in the MySQL pattern, matching PostgreSQL, so the replacement stops dropping it. closes: #71921 * Skip the non-finite float rewrite for XCom values that already parse as JSON If a value parses as JSON, any NaN or Infinity in it can only be inside a string, so the rewrite has nothing to fix and the value is left byte for byte alone. That is the shape reported in #71921 and it means the migration no longer edits the contents of a JSON string at all. The sanitizer is now two statements per dialect. The U+0000 strip runs first and unconditionally, only on rows that contain the escape; the non-finite rewrite runs second, only on rows that do not parse. The order matters: a value invalid only because of the escape would otherwise look like it needs the rewrite and be corrupted by it. Rows that do need the rewrite still get bare null, since a value can be invalid at the top level and also wrap an escaped document, and only null is valid at every nesting depth. PostgreSQL has no non-throwing JSON validator before 16 and 14 is still supported, so the check goes through a session-local pg_temp function with a cheap regex pre-test. MySQL and SQLite use the native JSON_VALID, with a JSON1 probe and an unguarded fallback on SQLite as in migration 0117. The guard also shrinks the documented SQLite false positive, since a value holding "NaN detected" now parses and is skipped. closes: #71921 * Narrow the SQLite JSON1 probe to OperationalError in migration 0049 A missing json_valid() raises OperationalError. Catching every exception also swallowed connection failures and silently sanitized without the guard, rewriting rows that already parse. (cherry picked from commit 6b60399)
ephraimbuddy
approved these changes
Sep 10, 2026
kravii
pushed a commit
to acceldata-io/airflow
that referenced
this pull request
Nov 19, 2026
… JSONB migration (apache#71926) (apache#72886) * Guard JSONB migration against invalid bytes conversion (apache#69064) Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 54f4300) * Do not corrupt XCom values that already parse as JSON in the bytea to JSONB migration (apache#71926) * Substitute null for non-finite floats in the XCom bytea to JSONB migration The sanitizer in 0049 wrapped NaN/Infinity/-Infinity in unescaped double quotes, which is only valid at the top level of a JSON document. When the XCom value is a JSON string wrapping another JSON document every interior quote is backslash-escaped, so the injected quote closes the wrapping string and the bytea -> JSONB cast aborts. null needs no quoting, so it is correct at any nesting depth. Also moves the run of spaces after the delimiter inside group 1 in the MySQL pattern, matching PostgreSQL, so the replacement stops dropping it. closes: apache#71921 * Skip the non-finite float rewrite for XCom values that already parse as JSON If a value parses as JSON, any NaN or Infinity in it can only be inside a string, so the rewrite has nothing to fix and the value is left byte for byte alone. That is the shape reported in apache#71921 and it means the migration no longer edits the contents of a JSON string at all. The sanitizer is now two statements per dialect. The U+0000 strip runs first and unconditionally, only on rows that contain the escape; the non-finite rewrite runs second, only on rows that do not parse. The order matters: a value invalid only because of the escape would otherwise look like it needs the rewrite and be corrupted by it. Rows that do need the rewrite still get bare null, since a value can be invalid at the top level and also wrap an escaped document, and only null is valid at every nesting depth. PostgreSQL has no non-throwing JSON validator before 16 and 14 is still supported, so the check goes through a session-local pg_temp function with a cheap regex pre-test. MySQL and SQLite use the native JSON_VALID, with a JSON1 probe and an unguarded fallback on SQLite as in migration 0117. The guard also shrinks the documented SQLite false positive, since a value holding "NaN detected" now parses and is skipped. closes: apache#71921 * Narrow the SQLite JSON1 probe to OperationalError in migration 0049 A missing json_valid() raises OperationalError. Catching every exception also swallowed connection failures and silently sanitized without the guard, rewriting rows that already parse. (cherry picked from commit 6b60399) --------- Co-authored-by: Sean Muth <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Hemkumar Chheda <[email protected]> (cherry picked from commit 1ab3d9f)
senthh
pushed a commit
to acceldata-io/airflow
that referenced
this pull request
Nov 23, 2026
… JSONB migration (apache#71926) (apache#72886) * Guard JSONB migration against invalid bytes conversion (apache#69064) Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 54f4300) * Do not corrupt XCom values that already parse as JSON in the bytea to JSONB migration (apache#71926) * Substitute null for non-finite floats in the XCom bytea to JSONB migration The sanitizer in 0049 wrapped NaN/Infinity/-Infinity in unescaped double quotes, which is only valid at the top level of a JSON document. When the XCom value is a JSON string wrapping another JSON document every interior quote is backslash-escaped, so the injected quote closes the wrapping string and the bytea -> JSONB cast aborts. null needs no quoting, so it is correct at any nesting depth. Also moves the run of spaces after the delimiter inside group 1 in the MySQL pattern, matching PostgreSQL, so the replacement stops dropping it. closes: apache#71921 * Skip the non-finite float rewrite for XCom values that already parse as JSON If a value parses as JSON, any NaN or Infinity in it can only be inside a string, so the rewrite has nothing to fix and the value is left byte for byte alone. That is the shape reported in apache#71921 and it means the migration no longer edits the contents of a JSON string at all. The sanitizer is now two statements per dialect. The U+0000 strip runs first and unconditionally, only on rows that contain the escape; the non-finite rewrite runs second, only on rows that do not parse. The order matters: a value invalid only because of the escape would otherwise look like it needs the rewrite and be corrupted by it. Rows that do need the rewrite still get bare null, since a value can be invalid at the top level and also wrap an escaped document, and only null is valid at every nesting depth. PostgreSQL has no non-throwing JSON validator before 16 and 14 is still supported, so the check goes through a session-local pg_temp function with a cheap regex pre-test. MySQL and SQLite use the native JSON_VALID, with a JSON1 probe and an unguarded fallback on SQLite as in migration 0117. The guard also shrinks the documented SQLite false positive, since a value holding "NaN detected" now parses and is skipped. closes: apache#71921 * Narrow the SQLite JSON1 probe to OperationalError in migration 0049 A missing json_valid() raises OperationalError. Catching every exception also swallowed connection failures and silently sanitized without the guard, rewriting rows that already parse. (cherry picked from commit 6b60399) --------- Co-authored-by: Sean Muth <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Hemkumar Chheda <[email protected]> (cherry picked from commit 1ab3d9f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #71926 to
v3-3-testfor the 3.3.2 release, including its prerequisite #69064.#71926 depends on #69064 ("Guard XCom/DagRun pickle-removal migrations 0049/0055 against NaN/Infinity and U+0000"), which was never backported to the 3.3 line (no milestone). Cherry-picking #71926 alone onto
v3-3-testconflicted (229-line divergence in0049) because #69064 was missing. With #69064 applied first, both cherry-pick cleanly.Both commits are included in chronological order:
#69064— guard the bytea→JSONB conversion against invalid bytes (NaN/Infinity/U+0000)#71926— do not corrupt XCom values that already parse as JSON (the target fix)Verification: the resulting migration SQL (
0049/0055) is byte-for-byte identical tomain(0 diff), i.e. exactly the SQL main's CI validated on Postgres and MySQL. ruff clean. The@pytest.mark.backend("postgres")/("mysql")migration tests included in these PRs run in this PR's CI DB matrix.Scope note: these are already-shipped 3.0.0 migrations, so the fix benefits deployments that have not yet run 0049/0055 (fresh installs / upgrades from pre-3.0); it does not re-run for deployments already on 3.x.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines