You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/03/10 12:01:28 UTC

[airflow] branch main updated: Fixing broken filter in in /taskinstance/list view (#29850)

This is an automated email from the ASF dual-hosted git repository.

potiuk 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 a3c9902bc6 Fixing broken filter in in /taskinstance/list view (#29850)
a3c9902bc6 is described below

commit a3c9902bc606f0c067a45f09e9d3d152058918e9
Author: Sam Wheating <sa...@gmail.com>
AuthorDate: Fri Mar 10 04:01:15 2023 -0800

    Fixing broken filter in in /taskinstance/list view (#29850)
---
 airflow/models/taskinstance.py |  9 ++++++++-
 tests/www/views/test_views.py  | 13 +++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py
index 1a826bc918..951bebd3a4 100644
--- a/airflow/models/taskinstance.py
+++ b/airflow/models/taskinstance.py
@@ -139,6 +139,13 @@ if TYPE_CHECKING:
     from airflow.models.operator import Operator
     from airflow.utils.task_group import MappedTaskGroup, TaskGroup
 
+    # This is a workaround because mypy doesn't work with hybrid_property
+    # TODO: remove this hack and move hybrid_property back to main import block
+    # See https://github.com/python/mypy/issues/4430
+    hybrid_property = property
+else:
+    from sqlalchemy.ext.hybrid import hybrid_property
+
 
 PAST_DEPENDS_MET = "past_depends_met"
 
@@ -561,7 +568,7 @@ class TaskInstance(Base, LoggingMixin):
         self._log = logging.getLogger("airflow.task")
         self.test_mode = False  # can be changed when calling 'run'
 
-    @property
+    @hybrid_property
     def try_number(self):
         """
         Return the try number that this task number will be when it is actually
diff --git a/tests/www/views/test_views.py b/tests/www/views/test_views.py
index 1d697f994c..053704fb05 100644
--- a/tests/www/views/test_views.py
+++ b/tests/www/views/test_views.py
@@ -146,6 +146,19 @@ def test_task_start_date_filter(admin_client, url, content):
     check_content_in_response(content, resp)
 
 
+@pytest.mark.parametrize(
+    "url",
+    [
+        "/taskinstance/list/?_flt_1_try_number=0",  # greater than
+        "/taskinstance/list/?_flt_2_try_number=5",  # less than
+    ],
+)
+def test_try_number_filter(admin_client, url):
+    resp = admin_client.get(url)
+    # Ensure that the taskInstance view can filter on gt / lt try_number
+    check_content_in_response("List Task Instance", resp)
+
+
 @pytest.mark.parametrize(
     "url, content",
     [