Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ $ dynaconf validate
This returns code 0 (success) if validation is ok.


!!! info
All values in dynaconf are parsed using toml format, TOML tries to be smart
and infer the type of the settings variables, some variables will be automatically
converted to integer:

FOO = "0x..." # hexadecimal
FOO = "0o..." # Octal
FOO = "0b..." # Binary

All cases are on toml specs https://github.com/toml-lang/toml/blob/master/toml.abnf

If you need to force a specific type casting there are 2 options.

1. Use double quoted for strings ex: `FOO = "'0x...'" will be string.
2. Specify the type using `@` ex: FOO = "@str 0x..."
(available converters are `@int, @float, @bool, @json`)

## Selective Validation

> **New in 3.1.6**
Expand Down
7 changes: 7 additions & 0 deletions dynaconf/utils/parse_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ def parse_conf_data(data, tomlfy=False, box_settings=None):
)
return _parsed

if (
isinstance(data, str)
and data.startswith(("+", "-"))
and data[1:].isdigit()
):
return data

# return parsed string value
return _parse_conf_data(data, tomlfy=tomlfy, box_settings=box_settings)

Expand Down
17 changes: 17 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from dynaconf import Dynaconf
from dynaconf import LazySettings
from dynaconf import ValidationError
from dynaconf import Validator
Expand Down Expand Up @@ -659,3 +660,19 @@ def test_validator_descriptions_flat(tmpdir):
"a": "a",
"b": "a",
}


def test_toml_should_not_change_validator_type_with_is_type_set():
settings = Dynaconf(
validators=[Validator("TEST", is_type_of=str, default="+172800")]
)

assert settings.test == "+172800"


def test_toml_should_not_change_validator_type_using_at_sign():
settings = Dynaconf(
validators=[Validator("TEST", is_type_of=str, default="@str +172800")]
)

assert settings.test == "+172800"