fix(providers/standard): improve error message for non-serializable op_kwargs in virtualenv operators#63270
Open
YoannAbriel wants to merge 2 commits intoapache:mainfrom
Open
fix(providers/standard): improve error message for non-serializable op_kwargs in virtualenv operators#63270YoannAbriel wants to merge 2 commits intoapache:mainfrom
YoannAbriel wants to merge 2 commits intoapache:mainfrom
Conversation
Member
|
@YoannAbriel This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. If you have questions, feel free to ask on the Airflow Slack. |
…p_kwargs in PythonVirtualenvOperator
When render_template_as_native_obj=True, templates like {{ ti }} resolve to
live Airflow objects that can't be pickled. The resulting PicklingError from
structlog internals is confusing and doesn't point to the root cause.
Catch serialization failures in _write_args, identify which specific kwargs
failed, and raise a clear AirflowException naming the bad keys and suggesting
to use string attributes instead.
Closes: apache#61741
94227ba to
0d56a12
Compare
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.
Problem
When
render_template_as_native_obj=Trueon a DAG, templates like{{ ti }}inop_kwargsresolve to liveTaskInstanceobjects instead of strings. WhenPythonVirtualenvOperator._write_argstries to pickle these for the subprocess, it fails with aPicklingErrorfrom structlog internals (Only BytesLoggers to sys.stdout and sys.stderr can be pickled). The error gives no indication that the root cause is a non-serializable kwarg value.Root Cause
_write_argscallsself.pickling_library.dumps(...)on the full args dict without any pre-validation. When a value can't be pickled, the raw exception propagates — and sinceTaskInstancecontains structlog loggers, the error message references structlog internals rather than the actual problem.Fix
Wrap the
dumpscall in a try/except. On failure, iterate overop_kwargsto identify which specific keys hold non-serializable values, then raise anAirflowExceptionnaming the bad keys and suggesting alternatives (e.g.{{ ti.task_id }}instead of{{ ti }}).Added a unit test that verifies the improved error message when a non-serializable object is passed in
op_kwargs.Closes: #61741
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.