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

Allow merge_unique on lists when merge_enabled=True #810

Merged
merged 1 commit into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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