Skip to content

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

@m3nadav

Description

@m3nadav

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a BugNot a Problem, expected behaviorRFC

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions