diff --git a/docs/validation.md b/docs/validation.md index c3d689483..4d1f8bb45 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -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** diff --git a/dynaconf/utils/parse_conf.py b/dynaconf/utils/parse_conf.py index 89be721c7..155f7cf89 100644 --- a/dynaconf/utils/parse_conf.py +++ b/dynaconf/utils/parse_conf.py @@ -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) diff --git a/tests/test_validators.py b/tests/test_validators.py index 9a592e29f..4ada62236 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -2,6 +2,7 @@ import pytest +from dynaconf import Dynaconf from dynaconf import LazySettings from dynaconf import ValidationError from dynaconf import Validator @@ -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"