Skip to content

Commit 672470a

Browse files
author
Cloud Composer Team
committed
fixup! Composer webserver patch
Cherry-pick apache/airflow#41350 Change-Id: If9d27e06c3f9a686b5d9869986c6a92213d6b83a GitOrigin-RevId: 70abf450fd69e59ef79f7ed9addde9900761e229
1 parent bf14c38 commit 672470a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

airflow/www/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ def trigger(self, dag_id: str, session: Session = NEW_SESSION):
20232023
.limit(num_recent_confs)
20242024
)
20252025
recent_confs = {
2026-
run_id: json.dumps(run_conf)
2026+
run_id: json.dumps(run_conf, cls=utils_json.WebEncoder)
20272027
for run_id, run_conf in ((run.run_id, run.conf) for run in recent_runs)
20282028
if isinstance(run_conf, dict) and any(run_conf)
20292029
}
@@ -2058,6 +2058,7 @@ def trigger(self, dag_id: str, session: Session = NEW_SESSION):
20582058
},
20592059
indent=4,
20602060
ensure_ascii=False,
2061+
cls=utils_json.WebEncoder,
20612062
)
20622063
except TypeError:
20632064
flash("Could not pre-populate conf field due to non-JSON-serializable data-types")

tests/www/views/test_views_trigger_dag.py

+28
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import datetime
2121
import json
22+
from decimal import Decimal
2223
from urllib.parse import quote
2324

2425
import pytest
@@ -28,6 +29,7 @@
2829
from airflow.operators.empty import EmptyOperator
2930
from airflow.security import permissions
3031
from airflow.utils import timezone
32+
from airflow.utils.json import WebEncoder
3133
from airflow.utils.session import create_session
3234
from airflow.utils.types import DagRunType
3335
from tests.test_utils.api_connexion_utils import create_test_client
@@ -92,6 +94,32 @@ def test_trigger_dag_conf(admin_client):
9294
assert run.conf == conf_dict
9395

9496

97+
def test_trigger_dag_conf_serializable_fields(admin_client):
98+
test_dag_id = "example_bash_operator"
99+
time_now = timezone.utcnow()
100+
conf_dict = {
101+
"string": "Hello, World!",
102+
"date_str": "2024-08-08T09:57:35.300858",
103+
"datetime": time_now,
104+
"decimal": Decimal(10.465),
105+
}
106+
expected_conf = {
107+
"string": "Hello, World!",
108+
"date_str": "2024-08-08T09:57:35.300858",
109+
"datetime": time_now.isoformat(),
110+
"decimal": 10.465,
111+
}
112+
113+
admin_client.post(f"dags/{test_dag_id}/trigger", data={"conf": json.dumps(conf_dict, cls=WebEncoder)})
114+
115+
with create_session() as session:
116+
run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
117+
assert run is not None
118+
assert DagRunType.MANUAL in run.run_id
119+
assert run.run_type == DagRunType.MANUAL
120+
assert run.conf == expected_conf
121+
122+
95123
def test_trigger_dag_conf_malformed(admin_client):
96124
test_dag_id = "example_bash_operator"
97125

0 commit comments

Comments
 (0)