[bug] Integer-like strings in validator defaults are incorrectly cast to integers
See original GitHub issueWhen specifying a default value for a validator of "+172800"
, dynaconf is casting the post-validation value to an integer 172800
. This is still true after explicitly adding is_type_of=str
to the validator.
Interestingly enough, performing another validation after this point fails the validation.
Validator section including the offending validator
Example of the problem
Dynaconf shouldn’t be explicitly casting default values to another type when not explicitly conflicting with the is_type_of
value.
Environment:
- OS: Fedora: 33
- Dynaconf Version: 3.1.4
- Frameworks in use: None
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
[bug] Integer-like strings in validator defaults are incorrectly ...
When specifying a default value for a validator of "+172800", dynaconf is casting the post-validation value to an integer 172800.
Read more >Integer and string cannot be distinguished with pydantic
strings are accepted as-is, int float and Decimal are coerced using ... str are converted using v.value, and all other types cause an...
Read more >Colander Basics - The Pylons Project
Let's define a schema which will attempt to convert a serialization to a data structure ... Int default = 10 title = 'Ranged...
Read more >Strings - Manual - PHP
A string is series of characters, where a character is the same as a byte. ... String offsets have to either be integers...
Read more >Custom pluggable types for ... - The Checker Framework Manual
-AcheckCastElementType In a cast, require that parameterized type arguments and array elements are the same. By default, the Checker ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JacobCallahan actually TOML takes more integer prefixes in to account https://github.com/toml-lang/toml/blob/master/toml.abnf#L116-L129
We can resolve the case for
+
and-
as suggested.But in any case, @andressadotpy we need to update the docs adding some notes like
@andressadotpy thanks for taking an interest in this issue! So the problem isn’t with the validator object itself, but when the default value is cast into a settings object.