Skip to content

Fix lookup_default leaking UNSET sentinel instead of None#1

Open
veeceey wants to merge 1 commit into
mainfrom
fix/issue-3145-lookup-default-unset
Open

Fix lookup_default leaking UNSET sentinel instead of None#1
veeceey wants to merge 1 commit into
mainfrom
fix/issue-3145-lookup-default-unset

Conversation

@veeceey
Copy link
Copy Markdown
Owner

@veeceey veeceey commented Feb 10, 2026

Summary

Fixes pallets#3145

Context.lookup_default() was returning the internal UNSET sentinel object instead of None when no default was found. This was a regression introduced in 8.3.0 that broke subclasses of Context which override lookup_default() and rely on the documented return type (Any | None).

  • Introduced a private _lookup_default() method that preserves the UNSET return value for internal use by Parameter.get_default() and Parameter.consume_value(), which need to distinguish "no default" from "default is None".
  • Made the public lookup_default() delegate to _lookup_default() and convert UNSET to None before returning, matching the documented return type and pre-8.3.0 behavior.

Test plan

  • Added test_lookup_default_returns_none_not_sentinel -- verifies lookup_default() returns None (not UNSET) in all "no default found" scenarios
  • Added test_lookup_default_subclass_no_sentinel_leak -- reproduces the exact pattern from the issue (subclass calling super().lookup_default() and checking is not None)
  • Full test suite passes (1233 passed, 22 skipped, 1 xfailed; the 1 collection error in test_basic.py is a pre-existing pytest compatibility issue unrelated to this change)

Context.lookup_default() returned the internal UNSET sentinel when no
default was found, which leaked an implementation detail to external
callers—particularly subclasses of Context that override the method and
check `if default is not None`.

Introduce a private _lookup_default() that preserves the UNSET return
for internal use (get_default and consume_value need to distinguish
"no default" from "default is None"), and make the public
lookup_default() convert UNSET to None before returning.

Fixes pallets#3145

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

lookup_default returns Sentinel.UNSET instead of None

1 participant