Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse bool values from environment variables #3204

Merged
merged 3 commits into from
Oct 13, 2022

Conversation

carandraug
Copy link
Contributor

This is similar in spirit to codalab/competitions-v1-compute-worker#24 but much more extensive to cover all other bool being read from environment variable.

I've noted that a proper check was already being done by AWS_S3_SECURE_URLS and AWS_QUERYSTRING_AUTH, each on their own way. I've changed them only for the sake of consistency.

Backwards compatibility note: this is not 100% backwards compatible. If someone was relying on setting an empty string to signal false, then this new behaviour is not compatible (but they'll get an error with a nice error message). I don't think that's expected since examples clearly use the string "False" for that. Similarly, if was someone was relying on setting some random string to signal true, then this change is also not backwards compatible (but again, they will get a nice error message). The only case where the new behaviour is incompatible and no error is raised is if they are setting the variables to one of ("n", "no", "f", "false", "off", "0") and expect them to be interpreted as true (hopefully no one is doing that).

The value of an environment variable is always a string and any
non-empty string evals as true.  If we want to support false values in
the text we need to parse it ourselves.

This commit fixes boolean options in the django settings file: DEBUG,
IS_DEV, EMAIL_USE_TLS, BROKER_USE_SSL, and PIN_PASSCODE_ENABLED.  In
addition, AWS_S3_SECURE_URLS and AWS_QUERYSTRING_AUTH parsed the
string value but in different manner.  This commit uses the same
approach in all, for the sake of consistency.

We drop the use of distutils.util.strtobool because distutils is
deprecated and will be removed in Python 3.12 but our implementation
is compatible.
Environment variables are strings and any non-empty string evals as
true.  This commit only checks if the value is "True" and something
fancier check True or False or error would be nicer but it's messy to
do it on a dockerfile RUN command that is sh appending to a python
file.
@Didayolo Didayolo merged commit fbbd12f into codalab:develop Oct 13, 2022
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.

3 participants