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

env.dict() splits on all separators rather than just first #471

Open
hrafnthor opened this issue May 1, 2023 · 1 comment
Open

env.dict() splits on all separators rather than just first #471

hrafnthor opened this issue May 1, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request need reproducible example Example is required to reproduce the issue

Comments

@hrafnthor
Copy link

hrafnthor commented May 1, 2023

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:

 { 'options': '-c search_path' }

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).

 { 'options': '-c search_path=<schema>;' }

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 in Env.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

@sergeyklay sergeyklay added the enhancement New feature or request label May 3, 2023
@sergeyklay
Copy link
Collaborator

Thank you for bringing this issue to our attention. To better understand the problem and evaluate your proposed solution, could you please provide a test case that demonstrates this issue? A test that highlights the current shortcomings would be extremely helpful. Looking forward to your input

@sergeyklay sergeyklay added the need reproducible example Example is required to reproduce the issue label Sep 9, 2023
@sergeyklay sergeyklay self-assigned this Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need reproducible example Example is required to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants