Open
Conversation
If you use empty values in your env files, e.g. `DB_PORT=` and cast it in call into int or float, so you will get an error: ``` ValueError: invalid literal for int() with base 10: '' ``` I just fixed that for me with this universal solution. It works not only on int or float
lucasrcezimbra
requested changes
Aug 25, 2025
Member
lucasrcezimbra
left a comment
There was a problem hiding this comment.
Please, add a test case to avoid regression.
Fix boolean conversions and empty-value handling across Decouple casting
logic to avoid treating empty strings as truthy or as missing in unexpected
ways.
- Return False for empty string in _cast_boolean instead of using bool('')
which is always False only accidentally; explicitly map '' -> False.
- When value is missing/empty and default is Undefined, if cast is the
boolean caster return False directly (preserve previous intent and avoid
falling through to unintended casts).
- Treat empty string the same as None in Transform.__call__ so that empty
values trigger post_process() rather than being stripped and cast, which
could lead to incorrect results.
These changes prevent empty strings from being misinterpreted by boolean
casts and ensure consistent handling of empty config values.
Add comprehensive unit tests verifying how empty values in env and ini repositories (and AutoConfig) are treated with defaults and casts. Key behavior validated: - Empty numeric values use provided numeric defaults when cast=int. - Empty values return None when default=None is specified. - Bool casts: empty value with default True returns True; without default, casting the empty value yields False. - CSV cast returns an empty list for an empty value and honors a provided default list. - Ensure RepositoryIni/RepositoryEnv and AutoConfig behavior is consistent. Also adjust existing tests to assert None is returned when default=None instead of expecting an empty string, aligning tests with intended semantics. Add fixtures and patched file IO (StringIO) to simulate .env/.ini files and avoid touching the filesystem.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you use empty values in your env files, e.g.
DB_PORT=and cast it in call into int or float, so you will get an error:I just fixed that for me with this universal solution. It works not only on int or float