Skip to content

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

@twosigmajab

Description

@twosigmajab

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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions