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

Casting Defaults; Question regarding ideal practice? #437

Open
hannylicious opened this issue Feb 8, 2023 · 2 comments
Open

Casting Defaults; Question regarding ideal practice? #437

hannylicious opened this issue Feb 8, 2023 · 2 comments
Labels
question Further information is requested

Comments

@hannylicious
Copy link

I was a little curious - in all the documentation it says to do something like this:

env = environ.Env(
    # set casting, default
    DEBUG=(bool, False),
)
DEBUG=env("DEBUG")
# I am adding these two for example purposes similar to documentation style
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
SECRET_KEY = env("DJANGO_SECRET_KEY")

Is there any benefit to casing and/or setting defaults to other things in the environ.Env() call? For example:

env = environ.Env(
    # set casting, default
    DEBUG=(bool, False),
    ALLOWED_HOSTS=(list, []),
    SECRET_KEY=(str, ""),
)
DEBUG=env("DEBUG")
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
SECRET_KEY = env("DJANGO_SECRET_KEY")

Is there any benefit to one way over the other? Is one better than the other or are they identical?

Or would something like this be better?

# default method, but casting the variables when setting them
env = environ.Env()
DEBUG=env.bool("DEBUG", default=False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
SECRET_KEY = env.str("DJANGO_SECRET_KEY", default="")

Just looking for thoughts on which is the 'ideal' way - any advice appreciated!

@sergeyklay sergeyklay added the question Further information is requested label Mar 1, 2023
@pataquets
Copy link

Also interested. If there is any significant difference, it would be great to know in order to improve docs.

@EnriqueSoria
Copy link

FYI this is what I do: https://blog.enriquesoria.com/mantainable-env-sample/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants