You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/29 13:38:18 UTC

[GitHub] [airflow] potiuk opened a new pull request, #27366: Fix coertion for VERBOSE and DRY_RUN env variables

potiuk opened a new pull request, #27366:
URL: https://github.com/apache/airflow/pull/27366

   The #27191 change introduced globally shareable flags for verbose and dry-run flags in Breeze however it also changed behaviour of the "false" string passed by VERBOSE/DRY_RUN env variables and crashed breeze when one of those variables was set to empty string.
   
   As a result CI's "VERBOSE" "false" flag in static checks was treated as "truthy" and static checks output contained a lot of noise from non-failing static checks.
   
   It turns out that "convert" method of click can also take "strings" as parameter because coertion of env variables happens inside the convert method (which mkes sense if you think about it) so the convert method should accept both string and target type values, This is explained in convert method docs but I missed it :(.
   
   This change fixes both problems by introducing explicit coertion of the variables from all kinds of string values - both when the flags are parsed but also before (sometimes we need verbose flag from variable (when we run breeze in scripts) even before the flag is actually parsed by click so additionally to coercing the flag, we also pre-emptively run the same coertion when importing the "shared_options" module.
   
   Also just for the sake of it, we accept all kinds of truth-y, falsy strings now - true/false/yes/no/t/f/y/n in all kinds of casing and shortcuts.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
pierrejeambrun commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008720461


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   is it possible to call `_coerce_bool_value` from here to not duplicate these lines ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008732726


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   Fixed. Take a look @pierrejeambrun :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #27366:
URL: https://github.com/apache/airflow/pull/27366#issuecomment-1295840171

   cc: @blag -> interesting click behaviour :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
pierrejeambrun commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008739005


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   Totally agree! I like your solution of extracting into it’s own module. Thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #27366:
URL: https://github.com/apache/airflow/pull/27366#issuecomment-1295857651

   Rsult of the fix.
   
   This:
   
   ![image](https://user-images.githubusercontent.com/595491/198837715-cbe854bc-2146-47ed-b1ac-ffe6d33bca80.png)
   
   Looks way better than this:
   
   ![image](https://user-images.githubusercontent.com/595491/198837796-c51b27c1-668a-44c2-9ccd-ba7fea0ef91a.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
pierrejeambrun commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008739005


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   Totally agree! I have seen that before on other projects 😂. I like having  it’s own module for it. Thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
pierrejeambrun commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008739005


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   Totally agree! I like your solution of extracting into it’s own module. Thanks ! 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk merged pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
potiuk merged PR #27366:
URL: https://github.com/apache/airflow/pull/27366


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #27366: Fix coertion for VERBOSE and DRY_RUN env variables

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #27366:
URL: https://github.com/apache/airflow/pull/27366#discussion_r1008732466


##########
dev/breeze/src/airflow_breeze/utils/shared_options.py:
##########
@@ -19,7 +19,15 @@
 
 import os
 
-__verbose_value: bool = os.environ.get("VERBOSE", "false")[0].lower() == "t"
+
+def __get_default_bool_value(env_var: str) -> bool:
+    string_val = os.environ.get(env_var, "")
+    if not string_val:  # handle "" and other false-y coerce-able values
+        return False
+    return string_val[0].lower() in ["t", "y"]  # handle all kinds of truth-y/yes-y/false-y/non-sy strings

Review Comment:
   Very good point. 
   
   Generally I want to avoid the "airflow" fallacy where there are some intertwined imports between utils that are ending up often in circular references and local imports (hello `config` and `secrets`) so you have to be rather careful with such coupling of independent modules. Here the potential difficult lies with, the Custom Params and shared_options import sequence in various scenarios. 
   
   This would work in this case but I can imagine this migh be a problem - even accidentally - in the future so I think even better soluion is to extract coerce method to a separate module and use it in both places. I am rather aware of cyclomatic complexity https://en.wikipedia.org/wiki/Cyclomatic_complexity and while the ship has sailed for Airflow (or maybe we will be able to fix it over time who knows I tried to fix cyclomtic complexity for config few times and failed miserably) but I try to keep it low for breeze (even without measuring it). 
   
   Fix is coming.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org