24
24
from itsdangerous import URLSafeSerializer
25
25
from pendulum .tz .timezone import FixedTimezone , Timezone
26
26
from pydantic import (
27
- AliasChoices ,
27
+ AliasGenerator ,
28
28
BaseModel ,
29
- Field ,
29
+ ConfigDict ,
30
30
computed_field ,
31
31
field_validator ,
32
32
)
@@ -77,6 +77,14 @@ def get_owners(cls, v: Any) -> list[str] | None:
77
77
return v .split ("," )
78
78
return v
79
79
80
+ @field_validator ("timetable_summary" , mode = "before" )
81
+ @classmethod
82
+ def get_timetable_summary (cls , tts : str | None ) -> str | None :
83
+ """Validate the string representation of timetable_summary."""
84
+ if tts is None or tts == "None" :
85
+ return None
86
+ return str (tts )
87
+
80
88
# Mypy issue https://github.com/python/mypy/issues/1362
81
89
@computed_field # type: ignore[misc]
82
90
@property
@@ -103,9 +111,7 @@ class DAGDetailsResponse(DAGResponse):
103
111
"""Specific serializer for DAG Details responses."""
104
112
105
113
catchup : bool
106
- dag_run_timeout : timedelta | None = Field (
107
- validation_alias = AliasChoices ("dag_run_timeout" , "dagrun_timeout" )
108
- )
114
+ dag_run_timeout : timedelta | None
109
115
dataset_expression : dict | None
110
116
doc_md : str | None
111
117
start_date : datetime | None
@@ -114,11 +120,19 @@ class DAGDetailsResponse(DAGResponse):
114
120
orientation : str
115
121
params : abc .MutableMapping | None
116
122
render_template_as_native_obj : bool
117
- template_search_path : Iterable [str ] | None = Field (
118
- validation_alias = AliasChoices ("template_search_path" , "template_searchpath" )
119
- )
123
+ template_search_path : Iterable [str ] | None
120
124
timezone : str | None
121
- last_parsed : datetime | None = Field (validation_alias = AliasChoices ("last_parsed" , "last_loaded" ))
125
+ last_parsed : datetime | None
126
+
127
+ model_config = ConfigDict (
128
+ alias_generator = AliasGenerator (
129
+ validation_alias = lambda field_name : {
130
+ "dag_run_timeout" : "dagrun_timeout" ,
131
+ "last_parsed" : "last_loaded" ,
132
+ "template_search_path" : "template_searchpath" ,
133
+ }.get (field_name , field_name ),
134
+ )
135
+ )
122
136
123
137
@field_validator ("timezone" , mode = "before" )
124
138
@classmethod
@@ -128,14 +142,6 @@ def get_timezone(cls, tz: Timezone | FixedTimezone) -> str | None:
128
142
return None
129
143
return str (tz )
130
144
131
- @field_validator ("timetable_summary" , mode = "before" )
132
- @classmethod
133
- def get_timetable_summary (cls , tts : str | None ) -> str | None :
134
- """Validate the string representation of timetable_summary."""
135
- if tts is None or tts == "None" :
136
- return None
137
- return str (tts )
138
-
139
145
@field_validator ("params" , mode = "before" )
140
146
@classmethod
141
147
def get_params (cls , params : abc .MutableMapping | None ) -> dict | None :
0 commit comments