Skip to content

boolean values in environment variables#9535

Closed
christophlingg wants to merge 1 commit intoapache:masterfrom
christophlingg:patch-1
Closed

boolean values in environment variables#9535
christophlingg wants to merge 1 commit intoapache:masterfrom
christophlingg:patch-1

Conversation

@christophlingg
Copy link
Copy Markdown

@christophlingg christophlingg commented Jun 26, 2020

Some configuration variables are boolean and it was not clear to me how to set those bools from environmental variables which are all strings. Eventually, I found the mapping in the code.


Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Unit tests coverage for changes (not needed for documentation changes)
  • Target Github ISSUE in description if exists
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Jun 26, 2020

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://apache-airflow-slack.herokuapp.com/

Comment thread docs/howto/set-config.rst

.. code-block:: bask

export AIRFLOW__CORE__REMOTE_LOGGING=true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't matter. the values are read as string by the configparser

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export AIRFLOW__CORE__LOAD_DEFAULT_CONNECTIONS=Trueipython
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from airflow.configuration import  conf

In [2]: conf.getboolean("core", "load_default_connections")
Out[2]: True

In [3]:
Do you really want to exit ([y]/n)? yexport AIRFLOW__CORE__LOAD_DEFAULT_CONNECTIONS=Falseipython
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from airflow.configuration import  conf

In [2]: conf.getboolean("core", "load_default_connections")
Out[2]: False

In [3]:

Copy link
Copy Markdown
Member

@kaxil kaxil Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check line L330

def getboolean(self, section, key, **kwargs):
val = str(self.get(section, key, **kwargs)).lower().strip()
if '#' in val:
val = val.split('#')[0].strip()
if val in ('t', 'true', '1'):
return True
elif val in ('f', 'false', '0'):
return False
else:
raise AirflowConfigException(
f'Failed to convert value to bool. Please check "{key}" key in "{section}" section. '
f'Current value: "{val}".'
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @kaxil for getting into that. When I set the environmental variables I was not aware that airflow parses booleans that gracefully and supports many variants (1, TRUE, true, t, True, ...). One could avoid concerns by giving an example in the documentation, like I did above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even tRuE should work :) as we convert them to .lower() so it doesn't matter for a user until there is a Typo :)

If you think some docs around that can help ease the confusion, I am happy for you to update the docs in this PR and merge it :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I was thinking too much like a software developer here. And as the parsing is so clever, people won't have issues.

I will close the PR, thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants