fix(providers/standard): improve error message for non-serializable op_kwargs in virtualenv operators - #63270
Conversation
|
@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. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
…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
…p_kwargs in PythonVirtualenvOperator (apache#63270) 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
…p_kwargs in PythonVirtualenvOperator (apache#63270) 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
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.