-
-
Notifications
You must be signed in to change notification settings - Fork 318
Validator with different environments has weird behaviour #968
Copy link
Copy link
Closed
Labels
Milestone
Description
Describe the bug
When running MY_PROGRAM_STAGE=development python test.py, I get dynaconf.validator.ValidationError: TEST_1 is required in env production when the environment has been set to development.
To Reproduce
Steps to reproduce the behavior:
- Having the following folder structure
Project structure
.
├── test.py
└── test.yaml
1 directory, 2 files- Having the following config files:
Config files
test.yaml
production:
development:
TEST_2: "bar"- Having the following app code:
Code
test.py
from pathlib import Path
from dynaconf import Dynaconf, Validator
settings = Dynaconf(
settings_files=[Path.cwd() / "test.yaml"],
environments=True,
env_switcher="MY_PROGRAM_STAGE",
envvar_prefix="MY_PROGRAM",
merge_enabled=True,
validators=[
Validator("TEST_1", env="production", must_exist=True),
Validator("TEST_2", env="development", must_exist=True),
],
)
print(settings.items())- Executing under the following environment
Execution
* Python 3.10.8 (main, May 18 2023, 20:50:03) [Clang 14.0.3 (clang-1403.0.22.14.1)] * Poetry (version 1.4.2) * `dynaconf == 3.1.12`Expected behavior
Running MY_PROGRAM_STAGE=development python test.py should not fail because we're not running in production, so it shouldn't matter that there's no value for TEST_1.
Environment (please complete the following information):
- OS: MacOS 13.3.1 (22E261), M1 Pro.
- Python 3.10.8 (main, May 18 2023, 20:50:03) [Clang 14.0.3 (clang-1403.0.22.14.1)]
- Poetry (version 1.4.2)
dynaconf == 3.1.12- Frameworks in use: None.
Reactions are currently unavailable