jscheffl commented on code in PR #47050:
URL: https://github.com/apache/airflow/pull/47050#discussion_r3032154638


##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py:
##########
@@ -68,18 +104,52 @@ def convert_port(port) -> k8s.V1ContainerPort:
     return _convert_kube_model_object(port, k8s.V1ContainerPort)
 
 
-def convert_env_vars(env_vars: list[k8s.V1EnvVar] | dict[str, str]) -> 
list[k8s.V1EnvVar]:
+def convert_env_vars(
+    env_vars: list[k8s.V1EnvVar] | list[dict[str, Any]] | dict[str, str],
+) -> list[k8s.V1EnvVar]:
     """
     Coerce env var collection for kubernetes.
 
-    If the collection is a str-str dict, convert it into a list of 
``V1EnvVar`` variables.
+    Supported shapes:
+
+    * ``dict[str, str]``: mapping of env name to literal value (documented API 
style).
+    * ``list[k8s.V1EnvVar]``: pass through.
+    * ``list[dict]``: each element is either a minimal ``{"name": str, 
"value": ...}`` mapping
+      or a Kubernetes-API-shaped dict deserialized to ``V1EnvVar`` (e.g. with 
``valueFrom``).
+
+    The list-of-plain-dicts form was never described as a stable public 
contract in historical
+    Airflow docs; it appears in the wild from templated YAML/JSON and older 
examples. It is
+    therefore deprecated and may be removed in a future major 
``cncf.kubernetes`` release—prefer
+    ``dict[str, str]`` or ``list[V1EnvVar]``.
     """
     if isinstance(env_vars, dict):
         return [k8s.V1EnvVar(name=k, value=v) for k, v in env_vars.items()]
-    return env_vars
-
-
-def convert_env_vars_or_raise_error(env_vars: list[k8s.V1EnvVar] | dict[str, 
str]) -> list[k8s.V1EnvVar]:
+    if not isinstance(env_vars, list):
+        return env_vars  # type: ignore[return-value]
+    if not env_vars:
+        return []
+    all_v1 = all(isinstance(x, k8s.V1EnvVar) for x in env_vars)
+    all_dict = all(isinstance(x, dict) for x in env_vars)
+    if all_v1:
+        return env_vars
+    if all_dict:
+        warnings.warn(
+            "Passing env_vars as a list of {'name': ..., 'value': ...} dicts 
is deprecated; "
+            "this shape was not a documented first-class API. Use dict[str, 
str] "
+            "(environment name to value) or a list of k8s.V1EnvVar. "
+            "Support may be removed in a future major 
apache-airflow-providers-cncf-kubernetes release.",
+            AirflowProviderDeprecationWarning,
+            stacklevel=2,
+        )
+        return [_env_var_dict_to_v1(d, i) for i, d in enumerate(env_vars)]
+    raise AirflowException(

Review Comment:
   We defined as a community that that generic `AirflowException` is only 
existing for historic reasons. Codebase is in cleaning. Can you please use 
either a standard Python Exception (`ValueError`might be fitting here) or 
define a specific execption for this problem?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to