You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2025/10/16 16:34:41 UTC
[PR] Lazy import PodGenerator for deserialization [airflow]
potiuk opened a new pull request, #56733:
URL: https://github.com/apache/airflow/pull/56733
The #56692 introduced optimization for PodGenerator imports - but there was a problem that when deserializing Pod it failed when no k8s classes were loaded - but it really is not optimisation but failure - nothing actually prevents us from importing the k8s classes and we actually **have to** do it in case we want to deserialize serialized Pod.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! 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.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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] Lazy import PodGenerator for deserialization [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436897126
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
@potiuk This is a wrong fix! and will result in Scheduler or API-server crashing if k8s library was uninstalled/not-present anymore with weird errors
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #56733:
URL: https://github.com/apache/airflow/pull/56733#issuecomment-3412502423
### Backport failed to create: v3-1-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/18572183606'> Run details </a>
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>❌</td>
<td>v3-1-test</td>
<td><a href="https://github.com/apache/airflow/commit/17037e6a2cf7151c361bd611e20e96b68d3f6096"><img src='https://img.shields.io/badge/Commit-17037e6-red' alt='Commit Link'></a></td>
</tr>
</table>
You can attempt to backport this manually by running:
```bash
cherry_picker 17037e6 v3-1-test
```
This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
```bash
cherry_picker --continue
```
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436938783
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
Should be beter now.
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on PR #56733:
URL: https://github.com/apache/airflow/pull/56733#issuecomment-3412924409
> The log failures seems to be a different issue:
>
> ```
> E AssertionError: None of the log sources ['/opt/airflow/logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_pull/attempt=1.log'] were found in S3 bucket logs ['s3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=pull_value_from_bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=puller/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push_by_returning/attempt=1.log']
> E assert False
> E + where False = any(<generator object TestRemoteLogging.test_remote_logging_s3.<locals>.<genexpr> at 0x7f9cbe544dd0>)
>
> tests/airflow_e2e_tests/remote_log_tests/test_remote_logging.py:81: AssertionError
> =============================== warnings summary ===============================
> ../.venv/lib/python3.10/site-packages/testcontainers/core/waiting_utils.py:215
> /home/runner/work/airflow/airflow/.venv/lib/python3.10/site-packages/testcontainers/core/waiting_utils.py:215: DeprecationWarning: The @wait_container_is_ready decorator is deprecated and will be removed in a future version. Use structured wait strategies instead: container.waiting_for(HttpWaitStrategy(8080).for_status_code(200)) or container.waiting_for(LogMessageWaitStrategy('ready'))
> @wait_container_is_ready()
>
> -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
> =========================== short test summary info ============================
> FAILED tests/airflow_e2e_tests/remote_log_tests/test_remote_logging.py::TestRemoteLogging::test_remote_logging_s3 - AssertionError: None of the log sources ['/opt/airflow/logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_pull/attempt=1.log'] were found in S3 bucket logs ['s3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=pull_value_from_bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=puller/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push_by_returning/attempt=1.log']
> assert False
> + where False = any(<generator object TestRemoteLogging.test_remote_logging_s3.<locals>.<genexpr> at 0x7f9cbe544dd0>)
> ```
>
> cc @gopidesupavan if you have ideas
huh thats strange looks like logs endpoint returning local log location instead of remote location, though we have already configured remote logging.
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #56733:
URL: https://github.com/apache/airflow/pull/56733#issuecomment-3412500208
Yeah. Just looked :)
--
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] Lazy import PodGenerator for deserialization [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436899625
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
```suggestion
if not _has_kubernetes(force=True):
raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
```
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on PR #56733:
URL: https://github.com/apache/airflow/pull/56733#issuecomment-3412497408
The log failures seems to be a different issue:
```
E AssertionError: None of the log sources ['/opt/airflow/logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_pull/attempt=1.log'] were found in S3 bucket logs ['s3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=pull_value_from_bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=puller/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push_by_returning/attempt=1.log']
E assert False
E + where False = any(<generator object TestRemoteLogging.test_remote_logging_s3.<locals>.<genexpr> at 0x7f9cbe544dd0>)
tests/airflow_e2e_tests/remote_log_tests/test_remote_logging.py:81: AssertionError
=============================== warnings summary ===============================
../.venv/lib/python3.10/site-packages/testcontainers/core/waiting_utils.py:215
/home/runner/work/airflow/airflow/.venv/lib/python3.10/site-packages/testcontainers/core/waiting_utils.py:215: DeprecationWarning: The @wait_container_is_ready decorator is deprecated and will be removed in a future version. Use structured wait strategies instead: container.waiting_for(HttpWaitStrategy(8080).for_status_code(200)) or container.waiting_for(LogMessageWaitStrategy('ready'))
@wait_container_is_ready()
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/airflow_e2e_tests/remote_log_tests/test_remote_logging.py::TestRemoteLogging::test_remote_logging_s3 - AssertionError: None of the log sources ['/opt/airflow/logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_pull/attempt=1.log'] were found in S3 bucket logs ['s3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=pull_value_from_bash_push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=puller/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push/attempt=1.log', 's3://test-airflow-logs/dag_id=example_xcom_test/run_id=manual__2025-10-16T19:00:48.103160+00:00/task_id=push_by_returning/attempt=1.log']
assert False
+ where False = any(<generator object TestRemoteLogging.test_remote_logging_s3.<locals>.<genexpr> at 0x7f9cbe544dd0>)
```
cc @gopidesupavan if you have ideas
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436941276
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
The `force=True` alone will be enough without any changes. I had pushed a fix on your PR :) before your force-pushed it too :)
--
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] Lazy import PodGenerator for deserialization [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436915722
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
I see - but Right now it crashes if the other side has no k8s libraries installed (see main failures) - because it cannot deserialize the objects - so I guess we should simply silently ignore it
--
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] Lazy import PodGenerator for deserialization [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436897126
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
@potiuk This is a wrong fix! and will result in Scheduler or API-server crashing if k8s library was uninstalled/not-present anymore
--
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] Skip PodGenerator import for deserialization when no k8s installed [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil merged PR #56733:
URL: https://github.com/apache/airflow/pull/56733
--
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] Lazy import PodGenerator for deserialization [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #56733:
URL: https://github.com/apache/airflow/pull/56733#discussion_r2436904777
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -925,8 +925,11 @@ def deserialize(cls, encoded_var: Any) -> Any:
elif type_ == DAT.DATETIME:
return from_timestamp(var)
elif type_ == DAT.POD:
- if not _has_kubernetes():
- raise RuntimeError("Cannot deserialize POD objects without kubernetes libraries installed!")
+ # lazy import PogGenerator here if needed and set HAS_KUBERNETES to True and import the generator
+ # because if we need to deserialize Pod, we MUST have PodGenerator imported
+ _has_kubernetes(force=True)
+ from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
+
Review Comment:
It will already be imported by `_has_kubernetes` if k8s provider and library is installed after your "force" flag to recheck
--
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