Sanitize error message in DatabricksExecutionTrigger #70385
Open
fabbuc-gyg wants to merge 2 commits into
Open
Conversation
…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>
|
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
|
change comment
Contributor
|
cc @moomindani for Databricks team review |
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.
What
Strip characters that Postgres
jsonbcannot store (NUL bytes and unpaired UTF-16 surrogates) from a failed Databricks task's error text, in bothextract_failed_task_errorsandextract_failed_task_errors_async.Why
DatabricksExecutionTriggerputs each failed task's error into itsTriggerEventwhich gets persisted in the deferred task instance'snext_kwargs, which is a Postgresjsonbcolumn. Since Databricks output can contain NUL bytes, postgres rejects this with an error like this:Because the invalid event is retried, the triggerer enters a
CrashLoopBackOffwhich makes it unhealthy.How
A small
make_jsonb_safe()helper regex-strips\x00and\ud800-\udffffrom 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:make_jsonb_safecases (NUL strip, unpaired-surrogate strip, clean-text passthrough, non-string passthrough)extract_failed_task_errorsandextract_failed_task_errors_asyncsanitize error outputWas generative AI tooling used to co-author this PR?
Generated-by: Cursor
Made with Cursor