Skip to content

Commit

Permalink
[AIRFLOW-5387] Fix show paused pagination bug (apache#6100)
Browse files Browse the repository at this point in the history
(cherry picked from commit 93bb5e4)
  • Loading branch information
Alejandro Rojas authored and ashb committed Oct 14, 2019
1 parent 40df635 commit 2ed422a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 20 deletions.
17 changes: 15 additions & 2 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,26 @@ def is_accessible(self):


def get_params(**kwargs):
hide_paused_dags_by_default = conf.getboolean('webserver',
'hide_paused_dags_by_default')
if 'showPaused' in kwargs:
v = kwargs['showPaused']
if v or v is None:
show_paused_dags_url_param = kwargs['showPaused']
if _should_remove_show_paused_from_url_params(
show_paused_dags_url_param,
hide_paused_dags_by_default
):
kwargs.pop('showPaused')
return urlencode({d: v if v is not None else '' for d, v in kwargs.items()})


def _should_remove_show_paused_from_url_params(show_paused_dags_url_param,
hide_paused_dags_by_default):
return any([
show_paused_dags_url_param != hide_paused_dags_by_default,
show_paused_dags_url_param is None
])


def generate_pages(current_page, num_of_pages,
search=None, showPaused=None, window=7):
"""
Expand Down
17 changes: 15 additions & 2 deletions airflow/www_rbac/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,26 @@ def should_hide_value_for_key(key_name):


def get_params(**kwargs):
hide_paused_dags_by_default = conf.getboolean('webserver',
'hide_paused_dags_by_default')
if 'showPaused' in kwargs:
v = kwargs['showPaused']
if v or v is None:
show_paused_dags_url_param = kwargs['showPaused']
if _should_remove_show_paused_from_url_params(
show_paused_dags_url_param,
hide_paused_dags_by_default
):
kwargs.pop('showPaused')
return urlencode({d: v if v is not None else '' for d, v in kwargs.items()})


def _should_remove_show_paused_from_url_params(show_paused_dags_url_param,
hide_paused_dags_by_default):
return any([
show_paused_dags_url_param != hide_paused_dags_by_default,
show_paused_dags_url_param is None
])


def generate_pages(current_page, num_of_pages,
search=None, showPaused=None, window=7):
"""
Expand Down
42 changes: 34 additions & 8 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import mock
import six
from six.moves.urllib.parse import parse_qs, quote_plus
from parameterized import parameterized

from airflow.models import DagRun, Log, DagBag
from airflow.settings import Session
from airflow.utils.state import State
from airflow.utils import dates, timezone
from airflow.www import utils, app as application
from tests.test_utils.config import conf_vars

if six.PY2:
# Need `assertRegex` back-ported from unittest2
Expand Down Expand Up @@ -117,14 +119,38 @@ def test_params_search(self):
self.assertEqual('search=bash_',
utils.get_params(search='bash_'))

def test_params_showPaused_true(self):
"""Should detect True as default for showPaused"""
self.assertEqual('',
utils.get_params(showPaused=True))

def test_params_showPaused_false(self):
self.assertEqual('showPaused=False',
utils.get_params(showPaused=False))
@parameterized.expand([
(True, False, ''),
(False, True, ''),
(True, True, 'showPaused=True'),
(False, False, 'showPaused=False'),
(None, True, ''),
(None, False, ''),
])
def test_params_showPaused(self, show_paused, hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):
self.assertEqual(expected_result,
utils.get_params(showPaused=show_paused))

@parameterized.expand([
(True, False, True),
(False, True, True),
(True, True, False),
(False, False, False),
(None, True, True),
(None, False, True),
])
def test_should_remove_show_paused_from_url_params(self, show_paused,
hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):

self.assertEqual(
expected_result,
utils._should_remove_show_paused_from_url_params(
show_paused,
hide_by_default
)
)

def test_params_none_and_zero(self):
qs = utils.get_params(a=0, b=None)
Expand Down
43 changes: 35 additions & 8 deletions tests/www_rbac/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import six
from six.moves.urllib.parse import parse_qs

from parameterized import parameterized

from airflow.www_rbac import utils
from tests.test_utils.config import conf_vars

if six.PY2:
# Need `assertRegex` back-ported from unittest2
Expand Down Expand Up @@ -109,14 +112,38 @@ def test_params_search(self):
self.assertEqual('search=bash_',
utils.get_params(search='bash_'))

def test_params_showPaused_true(self):
"""Should detect True as default for showPaused"""
self.assertEqual('',
utils.get_params(showPaused=True))

def test_params_showPaused_false(self):
self.assertEqual('showPaused=False',
utils.get_params(showPaused=False))
@parameterized.expand([
(True, False, ''),
(False, True, ''),
(True, True, 'showPaused=True'),
(False, False, 'showPaused=False'),
(None, True, ''),
(None, False, ''),
])
def test_params_showPaused(self, show_paused, hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):
self.assertEqual(expected_result,
utils.get_params(showPaused=show_paused))

@parameterized.expand([
(True, False, True),
(False, True, True),
(True, True, False),
(False, False, False),
(None, True, True),
(None, False, True),
])
def test_should_remove_show_paused_from_url_params(self, show_paused,
hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):

self.assertEqual(
expected_result,
utils._should_remove_show_paused_from_url_params(
show_paused,
hide_by_default
)
)

def test_params_none_and_zero(self):
qs = utils.get_params(a=0, b=None)
Expand Down

0 comments on commit 2ed422a

Please sign in to comment.