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

fix ability to mix/merge json env variables with env_nested_delimiter… #3640

Closed
wants to merge 2 commits into from

Conversation

Air-Mark
Copy link
Contributor

@Air-Mark Air-Mark commented Jan 7, 2022

Change Summary

fix ability to mix/merge json env variables with variables defined according to env_nested_delimiter

Related issue number

Found a corner-case when we are mixing 2 types of nested environment variables definition.
#3159

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@Air-Mark Air-Mark marked this pull request as ready for review January 7, 2022 17:45
@Air-Mark
Copy link
Contributor Author

Air-Mark commented Jan 7, 2022

please review

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the request, but I'm not sure about the best way to proceed.

try:
env_val = settings.__config__.json_loads(env_val)
except JSONDecodeError:
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...
pass

if env_val:
try:
env_val = settings.__config__.json_loads(env_val)
except JSONDecodeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except JSONDecodeError:
except ValueError:

More consistent to just use ValueError

env_var[last_key] = env_val

if env_val:
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is we're calling json.loads on every field which:

  1. could have some weird side effects - e.g. you want "foobar" but json_loads converts it to foobar
  2. It could effect performance

We could:

  • not do this and document it?
  • check if env_val starts with { or [ and only parse json in that case

@samuelcolvin
Copy link
Member

please update.

@samuelcolvin
Copy link
Member

I think this overlaps a lot with #4216, but that solution is more complete, even that we're deferring to V2.

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

Successfully merging this pull request may close these issues.

None yet

3 participants