Skip to content

Comments

fix: lookup_default returns None instead of leaking internal sentinel#3209

Closed
karthiksai109 wants to merge 1 commit intopallets:mainfrom
karthiksai109:fix/lookup-default-returns-none-not-sentinel
Closed

fix: lookup_default returns None instead of leaking internal sentinel#3209
karthiksai109 wants to merge 1 commit intopallets:mainfrom
karthiksai109:fix/lookup-default-returns-none-not-sentinel

Conversation

@karthiksai109
Copy link

Fixes #3145

In 8.3.0, lookup_default started returning the internal Sentinel.UNSET
value instead of None when a key wasn't found in default_map. This broke
code that checked if default is not None since UNSET is not None.

Extracted the sentinel-aware logic into _lookup_default for internal use
by get_default and consume_value, and made the public lookup_default
convert UNSET to None before returning. This restores the pre-8.3.0
behavior for external callers while keeping the internal distinction
between "missing" and "explicitly None" intact.

Added a regression test covering all three cases: no default_map,
default_map without the key, and default_map with the key.

Fixes pallets#3145

In 8.3.0, lookup_default started returning the internal Sentinel.UNSET
value instead of None when a key wasn't found in default_map. This
broke code that relied on the pre-8.3.0 behavior where lookup_default
returned None for missing keys.

Extracted the sentinel-aware logic into _lookup_default for internal
use by get_default and consume_value, and made the public lookup_default
convert UNSET to None before returning.

Added a regression test covering all three cases: no default_map,
default_map without the key, and default_map with the key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lookup_default returns Sentinel.UNSET instead of None

3 participants