Skip to content

Conversation

@Gokujo
Copy link
Owner

@Gokujo Gokujo commented Aug 27, 2025

Title
fix-empty-values

Description
Correct boolean casting to explicitly map empty string -> False.

  • Ensure boolean caster returns False when value is missing/empty and default is Undefined.
  • Treat empty string the same as None in Transform.call so empty values trigger post_process() instead of being stripped and cast.
  • Add unit tests covering empty value handling for env/ini repositories and AutoConfig:
    • Empty numeric values use provided numeric defaults with cast=int.
    • Empty values return None when default=None.
    • Bool casts: empty value with default True returns True; without default, empty value casts to False.
    • CSV cast returns empty list for empty value and respects provided default list.
    • Ensure RepositoryIni/RepositoryEnv and AutoConfig behavior consistent.

Maxim Harder added 2 commits August 27, 2025 09:43
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.
@Gokujo Gokujo merged commit c448498 into patch-1 Aug 27, 2025
@Gokujo Gokujo deleted the fix-empty-values branch August 27, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants