[jira] [Commented] (AIRFLOW-2885) A Bug in www_rbac.utils.get_params
[ https://issues.apache.org/jira/browse/AIRFLOW-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16624363#comment-16624363 ] Xiaodong DENG commented on AIRFLOW-2885: Hi [~xnuinside] I realized this issue would not result in any actual exception in the UI (even it disobeys the zen "explicit is better than implicit" ;)) , so I closed the PR. Will close this Jira ticket now as well. Thanks for going through the tickets! > A Bug in www_rbac.utils.get_params > -- > > Key: AIRFLOW-2885 > URL: https://issues.apache.org/jira/browse/AIRFLOW-2885 > Project: Apache Airflow > Issue Type: Bug > Components: webserver >Reporter: Xiaodong DENG >Assignee: Xiaodong DENG >Priority: Critical > > *get_params(page=0, search="abc",showPaused=False)* returns > "_search=abc&showPaused=False_", while it's supposed to return > "page=0&search=abc&showPaused=False". > This is because Python takes 0 as False when it's used in a conditional > statement. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (AIRFLOW-2885) A Bug in www_rbac.utils.get_params
[ https://issues.apache.org/jira/browse/AIRFLOW-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16624074#comment-16624074 ] Iuliia Volkova commented on AIRFLOW-2885: - [~XD-DENG], why you close PR? will you work on this task? > A Bug in www_rbac.utils.get_params > -- > > Key: AIRFLOW-2885 > URL: https://issues.apache.org/jira/browse/AIRFLOW-2885 > Project: Apache Airflow > Issue Type: Bug > Components: webserver >Reporter: Xiaodong DENG >Assignee: Xiaodong DENG >Priority: Critical > > *get_params(page=0, search="abc",showPaused=False)* returns > "_search=abc&showPaused=False_", while it's supposed to return > "page=0&search=abc&showPaused=False". > This is because Python takes 0 as False when it's used in a conditional > statement. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (AIRFLOW-2885) A Bug in www_rbac.utils.get_params
[ https://issues.apache.org/jira/browse/AIRFLOW-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16581865#comment-16581865 ] ASF GitHub Bot commented on AIRFLOW-2885: - XD-DENG closed pull request #3731: [AIRFLOW-2885] Fix a bug in www_rbac.utils.get_params URL: https://github.com/apache/incubator-airflow/pull/3731 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/airflow/www_rbac/utils.py b/airflow/www_rbac/utils.py index 7bbdada555..ddbf90afd9 100644 --- a/airflow/www_rbac/utils.py +++ b/airflow/www_rbac/utils.py @@ -66,7 +66,7 @@ def get_params(**kwargs): if v or v is None: continue params.append('{}={}'.format(k, v)) -elif v: +elif v is not None: params.append('{}={}'.format(k, v)) params = sorted(params, key=lambda x: x.split('=')[0]) return '&'.join(params) diff --git a/tests/www_rbac/test_utils.py b/tests/www_rbac/test_utils.py index 05114881dd..1f5df30fd8 100644 --- a/tests/www_rbac/test_utils.py +++ b/tests/www_rbac/test_utils.py @@ -109,6 +109,11 @@ def test_params_all(self): self.assertEqual('page=3&search=bash_&showPaused=False', utils.get_params(showPaused=False, page=3, search='bash_')) +def test_params_all_page_zero(self): +"""Should return params string ordered by param key""" +self.assertEqual('page=0&search=bash_&showPaused=False', + utils.get_params(showPaused=False, page=0, search='bash_')) + if __name__ == '__main__': unittest.main() This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > A Bug in www_rbac.utils.get_params > -- > > Key: AIRFLOW-2885 > URL: https://issues.apache.org/jira/browse/AIRFLOW-2885 > Project: Apache Airflow > Issue Type: Bug > Components: webserver >Reporter: Xiaodong DENG >Assignee: Xiaodong DENG >Priority: Critical > > *get_params(page=0, search="abc",showPaused=False)* returns > "_search=abc&showPaused=False_", while it's supposed to return > "page=0&search=abc&showPaused=False". > This is because Python takes 0 as False when it's used in a conditional > statement. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (AIRFLOW-2885) A Bug in www_rbac.utils.get_params
[ https://issues.apache.org/jira/browse/AIRFLOW-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16581864#comment-16581864 ] ASF GitHub Bot commented on AIRFLOW-2885: - XD-DENG closed pull request #3731: [AIRFLOW-2885] Fix a bug in www_rbac.utils.get_params URL: https://github.com/apache/incubator-airflow/pull/3731 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/airflow/www_rbac/utils.py b/airflow/www_rbac/utils.py index 7bbdada555..ddbf90afd9 100644 --- a/airflow/www_rbac/utils.py +++ b/airflow/www_rbac/utils.py @@ -66,7 +66,7 @@ def get_params(**kwargs): if v or v is None: continue params.append('{}={}'.format(k, v)) -elif v: +elif v is not None: params.append('{}={}'.format(k, v)) params = sorted(params, key=lambda x: x.split('=')[0]) return '&'.join(params) diff --git a/tests/www_rbac/test_utils.py b/tests/www_rbac/test_utils.py index 05114881dd..1f5df30fd8 100644 --- a/tests/www_rbac/test_utils.py +++ b/tests/www_rbac/test_utils.py @@ -109,6 +109,11 @@ def test_params_all(self): self.assertEqual('page=3&search=bash_&showPaused=False', utils.get_params(showPaused=False, page=3, search='bash_')) +def test_params_all_page_zero(self): +"""Should return params string ordered by param key""" +self.assertEqual('page=0&search=bash_&showPaused=False', + utils.get_params(showPaused=False, page=0, search='bash_')) + if __name__ == '__main__': unittest.main() This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > A Bug in www_rbac.utils.get_params > -- > > Key: AIRFLOW-2885 > URL: https://issues.apache.org/jira/browse/AIRFLOW-2885 > Project: Apache Airflow > Issue Type: Bug > Components: webserver >Reporter: Xiaodong DENG >Assignee: Xiaodong DENG >Priority: Critical > > *get_params(page=0, search="abc",showPaused=False)* returns > "_search=abc&showPaused=False_", while it's supposed to return > "page=0&search=abc&showPaused=False". > This is because Python takes 0 as False when it's used in a conditional > statement. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (AIRFLOW-2885) A Bug in www_rbac.utils.get_params
[ https://issues.apache.org/jira/browse/AIRFLOW-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16575938#comment-16575938 ] ASF GitHub Bot commented on AIRFLOW-2885: - XD-DENG opened a new pull request #3731: [AIRFLOW-2885] Fix a bug in www_rbac.utils.get_params URL: https://github.com/apache/incubator-airflow/pull/3731 ### Jira - [x] My PR addresses the following [Airflow Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR" - https://issues.apache.org/jira/browse/AIRFLOW-2885 - In case you are fixing a typo in the documentation you can prepend your commit with \[AIRFLOW-XXX\], code changes always need a Jira issue. ### Description - [x] Here are some details about my PR, including screenshots of any UI changes: `get_params(page=0, search="abc",showPaused=False)` returns `search=abc&showPaused=False`, while it's supposed to return `page=0&search=abc&showPaused=False` (`page` is 0-indexed). This issue arose since `0` is considered as `False` by Python in conditional statement. `elif v` will not continue when `v` is `0` here, while it's supposed to continue. A test is added as well. ### Tests - [x] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason: ### Commits - [ ] My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)": 1. Subject is separated from body by a blank line 1. Subject is limited to 50 characters (not including Jira issue reference) 1. Subject does not end with a period 1. Subject uses the imperative mood ("add", not "adding") 1. Body wraps at 72 characters 1. Body explains "what" and "why", not "how" ### Documentation - [] In case of new functionality, my PR adds documentation that describes how to use it. - When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added. ### Code Quality - [x] Passes `git diff upstream/master -u -- "*.py" | flake8 --diff` This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > A Bug in www_rbac.utils.get_params > -- > > Key: AIRFLOW-2885 > URL: https://issues.apache.org/jira/browse/AIRFLOW-2885 > Project: Apache Airflow > Issue Type: Bug > Components: webserver >Reporter: Xiaodong DENG >Assignee: Xiaodong DENG >Priority: Critical > > *get_params(page=0, search="abc",showPaused=False)* returns > "_search=abc&showPaused=False_", while it's supposed to return > "page=0&search=abc&showPaused=False". > This is because Python takes 0 as False when it's used in a conditional > statement. -- This message was sent by Atlassian JIRA (v7.6.3#76005)