Skip to content

Commit

Permalink
Allow merge_unique on lists when merge_enabled=True (#810)
Browse files Browse the repository at this point in the history
Fix #726
  • Loading branch information
rochacbruno committed Sep 21, 2022
1 parent cacfa29 commit a7c706f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dynaconf/utils/__init__.py
Expand Up @@ -46,6 +46,12 @@ def object_merge(
return new

if isinstance(old, list) and isinstance(new, list):

# 726: allow local_merge to override global merge on lists
if "dynaconf_merge_unique" in new:
new.remove("dynaconf_merge_unique")
unique = True

for item in old[::-1]:
if unique and item in new:
continue
Expand Down
16 changes: 16 additions & 0 deletions tests_functional/issues/726_unique_nested_list/app.py
@@ -0,0 +1,16 @@
from __future__ import annotations

from dynaconf import Dynaconf

settings = Dynaconf(
envvar_prefix="ISSUE726",
settings_files=["defaults.yaml", "configuration.yaml"],
merge_enabled=True,
)


assert settings.config_key.nested_list == [
"item_a",
"item_b",
"item_c",
], settings.config_key.nested_list
@@ -0,0 +1,6 @@
config_key:
nested_list:
- dynaconf_merge_unique
- item_a
- item_b
- item_c
4 changes: 4 additions & 0 deletions tests_functional/issues/726_unique_nested_list/defaults.yaml
@@ -0,0 +1,4 @@
config_key:
nested_list:
- item_a
- item_b

0 comments on commit a7c706f

Please sign in to comment.