Taragolis commented on issue #38848:
URL: https://github.com/apache/airflow/issues/38848#issuecomment-2043607725
``render_template_as_native_obj=True,`` will force to use
`jinja2.nativetypes.NativeEnvironment` which are enforced to convert some to
python types, see example:
```python
from jinja2.sandbox import SandboxedEnvironment
from jinja2.nativetypes import NativeEnvironment
environments = {"sandboxed": SandboxedEnvironment(), "native":
NativeEnvironment()}
template = "4.0"
for name, env in environments.items():
print(f" Jinja2 Environment: {name} ".center(72, "="))
rendered = env.from_string("4.0").render()
print(f"Template: {template!r}")
print(f"Rendered: {rendered!r}, Type: {type(rendered).__name__!r}")
```
```console
==================== Jinja2 Environment: sandboxed =====================
Template: '4.0'
Rendered: '4.0', Type: 'str'
====================== Jinja2 Environment: native ======================
Template: '4.0'
Rendered: 4.0, Type: 'float'
```
There is two options here.
**Option 1**:
Do not use `jinja2.nativetypes.NativeEnvironment`, e.g.
`render_template_as_native_obj=True`
**Option 2** (Airflow 2.8+):
Use `airflow.template.templater.LiteralValue` (see:
https://github.com/apache/airflow/pull/35017) wrapper, which prevent template
values, e.g.
```diff
+from airflow.template.templater import LiteralValue
...
create_job_kwargs={
'WorkerType': 'G.2X',
'NumberOfWorkers': '1',
'DefaultArguments': {
'--datalake-formats': 'iceberg',
'--additional-python-modules': 'importlib',
},
- 'GlueVersion': '4.0'
+ 'GlueVersion': LiteralValue('4.0')
},
```
--
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]