You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ur...@apache.org on 2022/08/09 10:34:50 UTC
[airflow] branch main updated: Fix the errors raised when None is passed to template filters (#25593)
This is an automated email from the ASF dual-hosted git repository.
uranusjr 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 741c207702 Fix the errors raised when None is passed to template filters (#25593)
741c207702 is described below
commit 741c20770230c83a95f74fe7ad7cc9f95329f2cc
Author: Kian Eliasi <ki...@gmail.com>
AuthorDate: Tue Aug 9 15:04:40 2022 +0430
Fix the errors raised when None is passed to template filters (#25593)
---
airflow/templates.py | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/airflow/templates.py b/airflow/templates.py
index 6ec010f618..73c8635836 100644
--- a/airflow/templates.py
+++ b/airflow/templates.py
@@ -16,6 +16,10 @@
# specific language governing permissions and limitations
# under the License.
+from __future__ import annotations
+
+import datetime
+
import jinja2.nativetypes
import jinja2.sandbox
@@ -44,23 +48,33 @@ class SandboxedEnvironment(_AirflowEnvironmentMixin, jinja2.sandbox.SandboxedEnv
"""SandboxedEnvironment for Airflow task templates."""
-def ds_filter(value):
+def ds_filter(value: datetime.date | datetime.time | None) -> str | None:
+ if value is None:
+ return None
return value.strftime('%Y-%m-%d')
-def ds_nodash_filter(value):
+def ds_nodash_filter(value: datetime.date | datetime.time | None) -> str | None:
+ if value is None:
+ return None
return value.strftime('%Y%m%d')
-def ts_filter(value):
+def ts_filter(value: datetime.date | datetime.time | None) -> str | None:
+ if value is None:
+ return None
return value.isoformat()
-def ts_nodash_filter(value):
+def ts_nodash_filter(value: datetime.date | datetime.time | None) -> str | None:
+ if value is None:
+ return None
return value.strftime('%Y%m%dT%H%M%S')
-def ts_nodash_with_tz_filter(value):
+def ts_nodash_with_tz_filter(value: datetime.date | datetime.time | None) -> str | None:
+ if value is None:
+ return None
return value.isoformat().replace('-', '').replace(':', '')