pavelgein commented on code in PR #40165:
URL: https://github.com/apache/airflow/pull/40165#discussion_r1634085248
##########
airflow/providers/yandex/operators/dataproc.py:
##########
@@ -37,6 +37,25 @@ class InitializationAction:
timeout: int # Execution timeout
+# These two functions are needed, since when render_as_native_obj=True, Jinja
can deduce wrong types.
+# So we force elements to be string in API parameters
+# see https://github.com/apache/airflow/discussions/26336
+
+
+def force_dict_values_as_strings(dct: Optional[Dict[str, Any]]) ->
Optional[Dict[str, str]]:
+ if dct is None:
+ return None
+
+ return {k: str(v) for k, v in dct.items()}
+
+
+def force_list_values_as_string(lst: Optional[Iterable[Any]]) -> List[str]:
+ if lst is None:
+ return None
+
+ return list(map(str, lst))
+
+
Review Comment:
Could you, please, elaborate on this?
From the documentation,
> We can prevent airflow from treating this value as a reference to a file
by wrapping it in literal(). This approach disables the rendering of both
macros and files and can be applied to selected nested fields while retaining
the default templating rules for the remainder of the content.
But preventing from templating is not what I want.
The problem is, when some onepass, for example,
```
DataprocCreatePysparkJobOperator(..., args =
['{{params["parameter_with_int_value"]}}'])
```
Jinja Templating with `render_template_as_native_obj=True` will convert
`'{{params["parameter_with_int_value"]}}'` to `int` and the API call fails,
since it is required that `args` is a list of strings.
--
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]