Skip to content

[bug] validate_on_update causes AttributeError: 'Settings' object has no attribute 'ENVIRONMENTS_FOR_DYNACONF' #994

@LukeSavefrogs

Description

@LukeSavefrogs

Problem

Given this simple setup file:

from dynaconf import Dynaconf, Validator

settings = Dynaconf(
    settings_files=[
        'veryeasyfatt.config.toml',
        '.secrets.toml'
    ],
    merge_enabled=True,         # Merge all found files into one configuration.
    validate_on_update=True,    # Validate the configuration when it is updated.
    validators=[                # Custom validators.
        Validator(
            "files.output.kml",
            default="output.kml",
        ),
    ],
)

# Setup default values for missing settings (see #993)
if str(settings.files.output.kml.strip()) == "":
    settings.files.output.kml = "output.kml"

print(f"KML FILE: '{settings.files.output.kml}'")

NOTE: The actual configuration file is irrelevant, since it will fail anyway even if it doesn't actually exists.

When validate_on_update is set to True it always fails with the following stacktrace:

  File "d:\Progetti\danea-automation\src\veryeasyfatt\config.py", line 22, in <module>
    if settings.files.output.kml.strip() == "":
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 122, in __getattr__
    self._setup()
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 183, in _setup
    self._wrapped = self._wrapper_class(
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 262, in __init__
    self.set(key, value, loader_identifier="init_kwargs")
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 1018, in set
    self.validators.validate()
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\validator.py", line 492, in validate
    validator.validate(
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\validator.py", line 189, in validate
    self.envs = [settings.current_env]
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 309, in __getattribute__
    return super().__getattribute__(name)
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 746, in current_env
    if self.ENVIRONMENTS_FOR_DYNACONF is False:
  File "D:\Progetti\danea-automation\.venv\lib\site-packages\dynaconf\base.py", line 309, in __getattribute__
    return super().__getattribute__(name)
AttributeError: 'Settings' object has no attribute 'ENVIRONMENTS_FOR_DYNACONF'

What can I do to fix this? Is it my fault?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions