This is an automated email from the ASF dual-hosted git repository.
bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 4ce0cd5f13 Add WebEncoder for trigger page rendering to avoid render
failure (#41350)
4ce0cd5f13 is described below
commit 4ce0cd5f136ca6f7682ccb392c313a6e99912869
Author: M. Olcay Tercanlı <[email protected]>
AuthorDate: Mon Aug 12 21:06:54 2024 +0200
Add WebEncoder for trigger page rendering to avoid render failure (#41350)
---
airflow/www/views.py | 3 ++-
tests/www/views/test_views_trigger_dag.py | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 236beed451..a485f84ed4 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -2163,7 +2163,7 @@ class Airflow(AirflowBaseView):
.limit(num_recent_confs)
)
recent_confs = {
- run_id: json.dumps(run_conf)
+ run_id: json.dumps(run_conf, cls=utils_json.WebEncoder)
for run_id, run_conf in ((run.run_id, run.conf) for run in
recent_runs)
if isinstance(run_conf, dict) and any(run_conf)
}
@@ -2198,6 +2198,7 @@ class Airflow(AirflowBaseView):
},
indent=4,
ensure_ascii=False,
+ cls=utils_json.WebEncoder,
)
except TypeError:
flash("Could not pre-populate conf field due to
non-JSON-serializable data-types")
diff --git a/tests/www/views/test_views_trigger_dag.py
b/tests/www/views/test_views_trigger_dag.py
index c53213c3e6..9b2b297198 100644
--- a/tests/www/views/test_views_trigger_dag.py
+++ b/tests/www/views/test_views_trigger_dag.py
@@ -19,6 +19,7 @@ from __future__ import annotations
import datetime
import json
+from decimal import Decimal
from urllib.parse import quote
import pytest
@@ -28,6 +29,7 @@ from airflow.models.param import Param
from airflow.operators.empty import EmptyOperator
from airflow.security import permissions
from airflow.utils import timezone
+from airflow.utils.json import WebEncoder
from airflow.utils.session import create_session
from airflow.utils.types import DagRunType
from tests.test_utils.api_connexion_utils import create_test_client
@@ -92,6 +94,32 @@ def test_trigger_dag_conf(admin_client):
assert run.conf == conf_dict
+def test_trigger_dag_conf_serializable_fields(admin_client):
+ test_dag_id = "example_bash_operator"
+ time_now = timezone.utcnow()
+ conf_dict = {
+ "string": "Hello, World!",
+ "date_str": "2024-08-08T09:57:35.300858",
+ "datetime": time_now,
+ "decimal": Decimal(10.465),
+ }
+ expected_conf = {
+ "string": "Hello, World!",
+ "date_str": "2024-08-08T09:57:35.300858",
+ "datetime": time_now.isoformat(),
+ "decimal": 10.465,
+ }
+
+ admin_client.post(f"dags/{test_dag_id}/trigger", data={"conf":
json.dumps(conf_dict, cls=WebEncoder)})
+
+ with create_session() as session:
+ run = session.query(DagRun).filter(DagRun.dag_id ==
test_dag_id).first()
+ assert run is not None
+ assert DagRunType.MANUAL in run.run_id
+ assert run.run_type == DagRunType.MANUAL
+ assert run.conf == expected_conf
+
+
def test_trigger_dag_conf_malformed(admin_client):
test_dag_id = "example_bash_operator"