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 2021/07/01 07:24:40 UTC

[airflow] branch main updated: Fix unchecked indexing in _build_metrics (#16744)

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 a2d6aa0  Fix unchecked indexing in _build_metrics (#16744)
a2d6aa0 is described below

commit a2d6aa07c9de83278eef14a228eb4a02ad43205c
Author: Emil Ejbyfeldt <ee...@liveintent.com>
AuthorDate: Thu Jul 1 09:24:16 2021 +0200

    Fix unchecked indexing in _build_metrics (#16744)
    
    I am not sure if this can happend in regular uses, but when running test
    cases `sys.argv` can be that args passed to the pytest. When this is the
    case it is definently possible for argv to only contain a single
    element.
---
 airflow/utils/cli.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/airflow/utils/cli.py b/airflow/utils/cli.py
index 2b5eb59..acdb291 100644
--- a/airflow/utils/cli.py
+++ b/airflow/utils/cli.py
@@ -115,7 +115,8 @@ def _build_metrics(func_name, namespace):
     sub_commands_to_check = {'users', 'connections'}
     sensitive_fields = {'-p', '--password', '--conn-password'}
     full_command = list(sys.argv)
-    if full_command[1] in sub_commands_to_check:
+    sub_command = full_command[1] if len(full_command) > 1 else None
+    if sub_command in sub_commands_to_check:
         for idx, command in enumerate(full_command):
             if command in sensitive_fields:
                 # For cases when password is passed as "--password xyz" (with space between key and value)