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")
I tried adding an additional config file to a Dynaconf instance with global merge set to
Trueand 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_uniqueinside nested listsAnother alternative could be using the
local_mergeflag 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
additional_config.yaml
Result config dictionary:
A possible solution for enabling the unique flag in nested lists is to add the following lines right before running
object_mergeon nested values (for Dynaconf 3.1.7 it stays indynaconf/utils/__init__.py:77).