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] Recursive merge should allow unique flag in nested lists #726

Closed
m3nadav opened this issue Mar 15, 2022 · 2 comments · Fixed by #810
Closed

[RFC] Recursive merge should allow unique flag in nested lists #726

m3nadav opened this issue Mar 15, 2022 · 2 comments · Fixed by #810
Labels
Not a Bug Not a Problem, expected behavior RFC
Milestone

Comments

@m3nadav
Copy link

m3nadav commented Mar 15, 2022

I tried adding an additional config file to a Dynaconf instance with global merge set to True and found that a nested list was normally merged when I needed it to be unique or not merged at all as the old value was contained in the new value so the result list had duplicate items.
I thought about using a set instead but the order is important in this case

I'd like to be able to use dynaconf_merge_unique inside nested lists

Another alternative could be using the local_merge flag to allow disabling the merge for a specific nested value.
Although this alternative is more robust and general, it requires a more complex change than enabling the unique flag in nested lists

Example:

defaults.yaml

config_key:
  nested_list:
    - item_a
    - item_b

additional_config.yaml

config_key:
  nested_list:
    - item_a
    - item_b
    - item_c

Result config dictionary:

{
    "config_key":
        "nested_list": [item_a, item_b, item_a, item_b, item_c]
}

A possible solution for enabling the unique flag in nested lists is to add the following lines right before running object_merge on nested values (for Dynaconf 3.1.7 it stays in dynaconf/utils/__init__.py:77).

    unique = ("dynaconf_merge_unique" in value)

    if unique:
        value.remove("dynaconf_merge_unique")
@m3nadav m3nadav added Not a Bug Not a Problem, expected behavior RFC labels Mar 15, 2022
@rochacbruno rochacbruno added this to the 3.2.0 milestone Mar 31, 2022
@stale
Copy link

stale bot commented Jun 29, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@rochacbruno
Copy link
Member

#810

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

Successfully merging a pull request may close this issue.

2 participants