You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ephraimbuddy (via GitHub)" <gi...@apache.org> on 2026/06/22 15:56:19 UTC
[PR] Make cncf.kubernetes model deserialization picklable in-cluster [airflow]
ephraimbuddy opened a new pull request, #68848:
URL: https://github.com/apache/airflow/pull/68848
The kubernetes client (v36) attaches the process-global in-cluster Configuration to every model it deserializes, and that Configuration's refresh_api_key_hook is an unpicklable local closure. Any deserialized model that later gets pickled -- for example a pod_override placed on the KubernetesExecutor multiprocessing queue -- then crashes.
Deserialize through an ApiClient built with a fresh Configuration in the provider's model-deserialization paths so the resulting models (and every nested object) stay picklable regardless of the kubernetes client version: PodGenerator.deserialize_model_dict, KubernetesJobOperator.deserialize_job_template_file, and the backcompat _convert_from_dict converter.
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull request.
Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the documentation.
For user-facing UI changes, please attach before/after screenshots (or a short
screen recording) so reviewers can assess the visual impact.
Feel free to ping (in general) for the review if you do not see reaction for a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
- [x] Yes (please specify the tool below)
claude opus 4.8
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Make cncf.kubernetes model deserialization picklable in-cluster [airflow]
Posted by "ephraimbuddy (via GitHub)" <gi...@apache.org>.
ephraimbuddy merged PR #68848:
URL: https://github.com/apache/airflow/pull/68848
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Make cncf.kubernetes model deserialization picklable in-cluster [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #68848:
URL: https://github.com/apache/airflow/pull/68848#discussion_r3457147481
##########
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/backcompat/test_backwards_compat_converters.py:
##########
@@ -102,6 +102,35 @@ def test_convert_from_dict_with_invalid_type():
assert str(exc_info.value) == "Expected dict or <class 'unittest.mock.Mock'>, got <class 'str'>"
+def test_convert_from_dict_is_picklable_in_cluster(monkeypatch):
+ """A model deserialized from a dict must not capture the unpicklable in-cluster Configuration.
+
+ In-cluster, the kubernetes client installs a process-global default ``Configuration`` whose
+ ``refresh_api_key_hook`` is an unpicklable local closure. ``_convert_from_dict`` must deserialize
+ through a fresh ``Configuration`` so the model (and every nested object) stays picklable.
+ """
+ import pickle
+
+ from kubernetes.client import Configuration
Review Comment:
Top level import pls.
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py:
##########
@@ -36,7 +36,10 @@ def _convert_from_dict(obj, new_class):
if isinstance(obj, new_class):
return obj
if isinstance(obj, dict):
- api_client = ApiClient()
+ # A fresh Configuration() keeps the deserialized model picklable: in-cluster, the kubernetes
+ # client (v36) would otherwise stamp the global Configuration, whose refresh_api_key_hook is
+ # an unpicklable local closure, onto the model and every nested object.
Review Comment:
This same comment seems to repeat 3 times - in here, in job.py and in pod_generator.py, one place is enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Make cncf.kubernetes model deserialization picklable in-cluster [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #68848:
URL: https://github.com/apache/airflow/pull/68848#discussion_r3458431794
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py:
##########
@@ -36,7 +36,8 @@ def _convert_from_dict(obj, new_class):
if isinstance(obj, new_class):
return obj
if isinstance(obj, dict):
- api_client = ApiClient()
+ # A fresh Configuration() keeps the deserialized model picklabled
Review Comment:
```suggestion
# A fresh Configuration() keeps the deserialized model picklable
```
##########
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/backcompat/test_backwards_compat_converters.py:
##########
@@ -102,6 +103,32 @@ def test_convert_from_dict_with_invalid_type():
assert str(exc_info.value) == "Expected dict or <class 'unittest.mock.Mock'>, got <class 'str'>"
+def test_convert_from_dict_is_picklable_in_cluster(monkeypatch):
+ """A model deserialized from a dict must not capture the unpicklable in-cluster Configuration.
+
+ In-cluster, the kubernetes client installs a process-global default ``Configuration`` whose
+ ``refresh_api_key_hook`` is an unpicklable local closure. ``_convert_from_dict`` must deserialize
+ through a fresh ``Configuration`` so the model (and every nested object) stays picklable.
+ """
+
+ def _make_unpicklable_hook():
+ def _refresh_api_key(config):
+ return None
+
+ return _refresh_api_key
+
Review Comment:
Is there a need for a wrapper function here? Can't we just do:
```python
def _refresh_api_key(config):
return None
dirty.refresh_api_key_hook = _refresh_api_key
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org