Skip to content

Sanitize error message in DatabricksExecutionTrigger #70385

Open
fabbuc-gyg wants to merge 2 commits into
apache:mainfrom
fabbuc-gyg:fix/databricks-sanitize-failed-task-error-jsonb
Open

Sanitize error message in DatabricksExecutionTrigger #70385
fabbuc-gyg wants to merge 2 commits into
apache:mainfrom
fabbuc-gyg:fix/databricks-sanitize-failed-task-error-jsonb

Conversation

@fabbuc-gyg

@fabbuc-gyg fabbuc-gyg commented Jul 24, 2026

Copy link
Copy Markdown

What

Strip characters that Postgres jsonb cannot store (NUL bytes and unpaired UTF-16 surrogates) from a failed Databricks task's error text, in both extract_failed_task_errors and extract_failed_task_errors_async.

Why

DatabricksExecutionTrigger puts each failed task's error into its TriggerEvent which gets persisted in the deferred task instance's next_kwargs, which is a Postgres jsonb column. Since Databricks output can contain NUL bytes, postgres rejects this with an error like this:

sqlalchemy.exc.DataError: (psycopg2.errors.UntranslatableCharacter) unsupported Unicode escape sequence
DETAIL: \u0000 cannot be converted to text.

Because the invalid event is retried, the triggerer enters a CrashLoopBackOff which makes it unhealthy.

How

A small make_jsonb_safe() helper regex-strips \x00 and \ud800-\udfff from the error string (non-string values pass through unchanged). It is applied to the extracted error in both the sync and async helpers, so the emitted trigger event is always persistable.

Tests

Added unit tests in providers/databricks/tests/unit/databricks/utils/test_databricks.py:

  • direct make_jsonb_safe cases (NUL strip, unpaired-surrogate strip, clean-text passthrough, non-string passthrough)
  • extract_failed_task_errors and extract_failed_task_errors_async sanitize error output

Was generative AI tooling used to co-author this PR?
  • Yes - Cursor was used to help draft this change; the author reviewed it.

Generated-by: Cursor

Made with Cursor

…in jsonb

Databricks run output is arbitrary external text and can contain NUL bytes or
unpaired UTF-16 surrogates (e.g. when a task emits binary data). A failed
task's error is placed in the DatabricksExecutionTrigger event and persisted
by Airflow into the deferred task instance's next_kwargs (a jsonb column).
Postgres jsonb rejects those characters, so the triggerer crashes on write
(psycopg2 UntranslatableCharacter) and, because the invalid event is retried,
enters a CrashLoopBackOff that stalls all deferrable tasks.

Strip these characters from the extracted error in both the sync and async
extract_failed_task_errors helpers before it is emitted in the event.

Signed-off-by: Fabian Bücheler <fabian.bucheler@getyourguide.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@boring-cyborg

boring-cyborg Bot commented Jul 24, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

change comment
@fabbuc-gyg fabbuc-gyg changed the title fix(databricks): sanitize failed-task error text so it can be stored in jsonb Sanitze error message Jul 24, 2026
@shahar1 shahar1 changed the title Sanitze error message Sanitize error message in DatabricksExecutionTrigger Jul 24, 2026
@eladkal

eladkal commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

cc @moomindani for Databricks team review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants