Skip to content

fix: lookup_default returns None instead of UNSET sentinel#3199

Closed
atulk-code wants to merge 1 commit intopallets:mainfrom
atulk-code:fix/lookup-default-returns-none
Closed

fix: lookup_default returns None instead of UNSET sentinel#3199
atulk-code wants to merge 1 commit intopallets:mainfrom
atulk-code:fix/lookup-default-returns-none

Conversation

@atulk-code
Copy link

Context.lookup_default() is a public API method that users can override or call directly. In Click 8.3.0, commit 1c20dc6 deferred UNSET normalization which caused lookup_default to return the internal UNSET sentinel instead of None when a parameter was not in the default_map.

This broke the public API contract - users expect None, not an internal sentinel object.

This fix:

  • Adds internal _lookup_default() method that returns UNSET for internal use
  • Modifies public lookup_default() to normalize UNSET to None
  • Updates internal callers to use _lookup_default()
  • Adds regression tests to verify the fix

Fixes #3145

Context.lookup_default() is a public API method that users can override
or call directly. In Click 8.3.0, commit 1c20dc6 deferred UNSET
normalization which caused lookup_default to return the internal UNSET
sentinel instead of None when a parameter was not in the default_map.

This broke the public API contract - users expect None, not an internal
sentinel object.

This fix:
- Adds internal _lookup_default() method that returns UNSET for internal use
- Modifies public lookup_default() to normalize UNSET to None
- Updates internal callers to use _lookup_default()
- Adds regression tests to verify the fix

Fixes pallets#3145
@davidism davidism closed this Jan 31, 2026
@davidism davidism reopened this Jan 31, 2026
@kdeldycke
Copy link
Collaborator

This looks a bit AI-generated. Don't know what pallets policy is on that front. In the mean time @atulk-code, can you confirm or deny it?

As for the solution, it is not bad. But the problem is adding a private _lookup_default() method, then referencing it in the code defeat the purpose of having a public lookup_default() in Click API. What I mean is that we expect Click itself to invoke the public lookup_default() everywhere in its code, so the user has the opportunity to alter its behavior. This is exactly what the user was complaining about in #3145.

You should add a unittest that is reproducing #3145 exactly, with its custom CustomClickContext. lookup_default method to understand the limitations of your solution.

@davidism davidism closed this Feb 18, 2026
@davidism
Copy link
Member

This is like the 6th person to AI generate this PR. I'm not interested in that.

@kdeldycke
Copy link
Collaborator

I'm back from other rabbit holes so I'll try to get back to work on Click. I guess I can fix that for good based on my feedback.

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