Skip to content

[bug] array entries duplicated with Validator using default for computed value. #905

@aqc-carlodri

Description

@aqc-carlodri

Describe the bug
An array in the env file get strangely duplicated when using a Validator to create a new entry with a computed value.

It seems related to the presence of a string or an integer as array members, and to the merge_enabled flag.

To Reproduce
Steps to reproduce the behavior:

  1. Having the following folder structure
Project structure
    .env
    .gitignore
    config.py
    settings.toml
  1. Having the following config files:
Config files

.env

DYNACONF_GROUP__TEST_LIST = ["'1'", "'2'"]   # double quotes to cast as string

DYNACONF_GROUP__ANOTHER = 45

and

settings.toml

[default.group]
another_setting = "ciao"
  1. Having the following app code:
Code

config.py

from dynaconf import Dynaconf, Validator

settings = Dynaconf(
    envvar_prefix="DYNACONF",
    settings_files=["settings.toml"],
    environments=True,
    load_dotenv=True,
    merge_enabled=True,
)


settings.validators.register(
    Validator("group.something_new", default=5),
)

settings.validators.validate()
  1. Executing under the following environment
Execution
dynaconf -i config.settings list

Expected behavior
This output:

Working in development environment
LOAD_DOTENV<bool> True
GROUP<dict> {'ANOTHER': 45,
 'TEST_LIST': ['1', '2'],
 'another_setting': 'ciao',
 'something_new': 5}

What happens instead
This output:

Working in development environment
LOAD_DOTENV<bool> True
GROUP<dict> {'ANOTHER': 45,
 'TEST_LIST': ["'1'", "'2'", '1', '2'],
 'another_setting': 'ciao',
 'something_new': 5}

Environment (please complete the following information):

  • OS: Windows 10x64
  • Dynaconf Version 3.1.12

Additional context
If you remove the merge_enabled flag, the problem does not occur. I know the flag is meaningless here but in more complex cases where it is needed the problem occurs identically.

I might be doing something wrong with the casting to string of those array elements, but I have tried some different ways and it still doesn't work (like with the @str format specifier).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions