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

Change (or at least document) surprising behavior parsing env var when explicitly set to empty string #71

Closed
twosigmajab opened this issue Apr 25, 2019 · 2 comments · Fixed by #73

Comments

@twosigmajab
Copy link

twosigmajab commented Apr 25, 2019

Environs users I'm supporting just hit this:

cat config/foo.env 
MYINT="0"
MYFLOAT="0.0"
MYBOOL="False"
MYSTR=""

➜ . config/foo.envpython3
...
>>> from environs import Env
>>> env = Env()
>>> env.int("MYINT")
0
>>> env.float("MYFLOAT")
0.0
>>> env.bool("MYBOOL")
False
>>> env.str("MYSTR")
<marshmallow.missing>

What? Expected empty string, as explicitly set:

>>> from os import environ
>>> environ["MYSTR"]
''

This violates reasonable assumptions that the type of the value returned by env.foo is always foo, as is otherwise consistent with env.bool, env.int, env.float, etc.:

>>> isinstance(env.str("MYSTR"), str)
False

In this use case, the user should not need to know what a marshmallow.missing is, as it is an implementation detail, and should get back the explicitly set value of empty string rather than needing special logic that knows how to deal with marshmallow.missing.

If the current behavior cannot be changed e.g. for compatibility reasons, it should at least be documented, as this seems like a common use case.

Happy to submit a PR if that would be of interest. Thanks!

@sloria
Copy link
Owner

sloria commented Apr 26, 2019

This does appear to be a bug; I'd expect an empty string to be returned instead of marshmallow.missing.

I can't look into it today, so would definitely appreciate a PR.

@hvtuananh
Copy link
Contributor

I'll prepare a PR next week

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

Successfully merging a pull request may close this issue.

3 participants