Skip to content

[bug] Validator only casts default value #834

@Wenzel

Description

@Wenzel

Describe the bug
The Validator cast function only casts the default value, if provided.
If the default value is erased, and then the validator is called to be validated, the cast doesn't happen as it should be.

To Reproduce
Steps to reproduce the behavior:
3. Having the following app code:

Code

/path/src/app.py

from dynaconf import Dynaconf, Validator

settings = Dynaconf(
    validators=[
        Validator("offset", default=1, cast=int)
    ]
)

settings.offset = '24'

settings.validators.validate()

print(type(settings.offset))
...

Expected behavior
The output should have been:

<class 'int'>

Actual behavior

<class 'str'>

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Dynaconf Version 3.1.11

This is unfortunately a major blocker for me as I would like to do advanced parsing, conversion and validation through the cast callable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions