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

[RFC] create a easy way to get a copy/view of a config with changes applied #512

Open
RonnyPfannschmidt opened this issue Feb 10, 2021 · 4 comments
Labels
Not a Bug Not a Problem, expected behavior RFC
Milestone

Comments

@RonnyPfannschmidt
Copy link

Is your feature request related to a problem? Please describe.

in the test automation for insights we use a dynaconf object for the overall configuration,
in some tests components must create a version of the configuration for the current environment with changes applied

for_env(...) unfortunately returns objects that change the original configuration

deepcopy unfortunately fails for our config objects with exceptions about modules not being pickle-able

Describe the solution you'd like

mysettings.copy_with_changes(**data_to_merge_in_on_top) creates a new settings object that allows wont affect mysettings and can be used

Describe alternatives you've considered

  • creating fresh configurations every time -> currently takes a while and also takes away potential/intended code based changes of the settings objects
@RonnyPfannschmidt RonnyPfannschmidt added Not a Bug Not a Problem, expected behavior RFC labels Feb 10, 2021
@RonnyPfannschmidt RonnyPfannschmidt changed the title [RFC] creae a easy way to create a copy/view of a config with changes applied [RFC] create a easy way to get a copy/view of a config with changes applied Feb 10, 2021
@rochacbruno rochacbruno added this to the 3.2.0 milestone Mar 2, 2021
@Samreay
Copy link

Samreay commented Jun 4, 2021

This is something I'd love to see as well. Despite __deepcopy__ and __copy__ being defined on the settings, using either throws an exception, so our current solution is to reload the settings, apply the overrides, get the _store, copy that, then reload the settings again, which is incredibly slow.

@timhoffm
Copy link

It would also be nice to have this as a context manager. Something like

with mysettings.updated(**data_to_merge_in_on_top):
    # do something
# back to normal

@RonnyPfannschmidt
Copy link
Author

@timhoffm that would be a hazardous foot gun if one uses anything that consumes the config to create nin volatile state (like db./api clients with wrong credentials)

@rochacbruno
Copy link
Member

@timhoffm you can already do what you said.

with settings.using_env("development", **changes):
    # do something with

# back to normal 

Notice that this is not thread safe and will be deprecated on 4.0.0 in favour of some new approach that will either be a .copy or the same context manager but returning a copy instead of mutating the same object

@rochacbruno rochacbruno modified the milestones: 3.2.0, 3.1.8 Mar 31, 2022
@rochacbruno rochacbruno modified the milestones: 3.1.9, 3.2.0 Jun 2, 2022
@rochacbruno rochacbruno modified the milestones: 3.2.0, 4.0.0 Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Bug Not a Problem, expected behavior RFC
Projects
None yet
Development

No branches or pull requests

4 participants