-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(validators): Stop converting default when is_type_of is set to str (
#1066) * fix(validators): Stop converting default when is_type_of is set to str When a validator defines both `is_type_of=str, default="0.30"` the validation process SHOULD NOT convert the default to a float, so the current solution was to bypass toml by adding extra quotes. NOTE: Future solution, in 4.0.0 will be to decouple defaults declaration from validation declaration, and completely remove the tomlfy function fix: #1064
- Loading branch information
1 parent
7bf799c
commit b528e92
Showing
3 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests_functional/issues/1064_validator_default_type/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
from dynaconf import Dynaconf | ||
from dynaconf import Validator | ||
|
||
# Load config files | ||
config = Dynaconf(settings_files=["settings.toml"]) | ||
|
||
|
||
validators = [ | ||
Validator( | ||
"version", | ||
is_type_of=str, | ||
default="0.30", # this must not be transformed to float | ||
apply_default_on_none=True, | ||
), | ||
] | ||
|
||
config.validators.register(*validators) | ||
config.validators.validate() | ||
|
||
|
||
print(type(config.version)) | ||
print(config.version) | ||
|
||
|
||
assert config.version == "0.30" | ||
assert isinstance(config.version, str) |
Empty file.