env.dict()
splits on all separators rather than just first
#471
Labels
enhancement
New feature or request
need reproducible example
Example is required to reproduce the issue
The issue at hand
When parsing a complex dict format as per the instructions found here the
Env.parse_value()
method splits on every separator, causing issues with fields that contain the separator in their value section.As an example, observe this environment variable containing options values for setting schema values for a PostgreSQL database connection:
DB_OPTIONS="options=-c search_path=<schema>;"
When parsed with
env.dict('DB_OPTIONS', cast={'value': str}, default={})
the resulting dictionary cuts off part of the value:Possible workaround
Trying to use
env.dict('DB_OPTIONS', cast=dict, default={})
results in the value being preserved, however the;
separator is left behind (which causes this particular option not to function).Proposed change
While it is possible to use the workaround mentioned above with an environment variable that uses
,
rather than;
as key/value separators works, I think it would make sense to add a maximum split value of 1 to relevant line inEnv.parse_value()
to bring the behaviour more in line with what would be expected to happen.The cast to
dict
line just below already does handle this case (which is why it works as a workaround).Versions
django-environ: 0.10.0
The text was updated successfully, but these errors were encountered: