ashb commented on a change in pull request #11558:
URL: https://github.com/apache/airflow/pull/11558#discussion_r506163065
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -187,12 +190,12 @@ def _serialize(cls, var: Any) -> Any: # Unfortunately
there is no support for r
{str(k): cls._serialize(v) for k, v in var.items()},
type_=DAT.DICT
)
- elif isinstance(var, k8s.V1Pod):
+ elif has_kubernetes and isinstance(var, k8s.V1Pod):
Review comment:
```suggestion
elif HAS_KUBERNETES and isinstance(var, k8s.V1Pod):
```
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -187,12 +190,12 @@ def _serialize(cls, var: Any) -> Any: # Unfortunately
there is no support for r
{str(k): cls._serialize(v) for k, v in var.items()},
type_=DAT.DICT
)
- elif isinstance(var, k8s.V1Pod):
+ elif has_kubernetes and isinstance(var, k8s.V1Pod):
json_pod = PodGenerator.serialize_pod(var)
return cls._encode(json_pod, type_=DAT.POD)
elif isinstance(var, list):
return [cls._serialize(v) for v in var]
- elif isinstance(var, k8s.V1Pod):
+ elif has_kubernetes and isinstance(var, k8s.V1Pod):
Review comment:
```suggestion
elif HAS_KUBERNETES and isinstance(var, k8s.V1Pod):
```
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -256,7 +259,7 @@ def _deserialize(cls, encoded_var: Any) -> Any: # pylint:
disable=too-many-retu
return SerializedBaseOperator.deserialize_operator(var)
elif type_ == DAT.DATETIME:
return pendulum.from_timestamp(var)
- elif type_ == DAT.POD:
+ elif has_kubernetes and type_ == DAT.POD:
Review comment:
Though I also wonder if it should be an error to try and deserialise a
pod without the kube modules installed?
So something like:
```suggestion
elif type_ == DAT.POD:
if not HAS_KUBERNETES:
raise RuntimeError("Cannot deserialize POD objects without
kubernetes libraries installed!")
```
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -256,7 +259,7 @@ def _deserialize(cls, encoded_var: Any) -> Any: # pylint:
disable=too-many-retu
return SerializedBaseOperator.deserialize_operator(var)
elif type_ == DAT.DATETIME:
return pendulum.from_timestamp(var)
- elif type_ == DAT.POD:
+ elif has_kubernetes and type_ == DAT.POD:
Review comment:
```suggestion
elif HAS_KUBERNETES and type_ == DAT.POD:
```
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -46,6 +39,16 @@
from airflow.utils.module_loading import import_string
from airflow.utils.task_group import TaskGroup
+try:
+ # isort: off
+ from kubernetes.client import models as k8s
+ from airflow.kubernetes.pod_generator import PodGenerator
+ # isort: on
+ has_kubernetes = True
+except ImportError:
+ has_kubernetes = False
Review comment:
```suggestion
HAS_KUBERNETES = True
except ImportError:
HAS_KUBERNETES = False
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]