[rejected AI] preserve default=None in map filter (#2165) - #2262
Closed
eminsk wants to merge 1 commit into
Closed
Conversation
When mapping over an attribute with default=None, make_attrgetter previously treated None as no default provided (if default is not None:), causing missing attributes to remain Undefined instead of defaulting to None. This resulted in UndefinedError under strict environments like Ansible. Use the missing sentinel so explicit default=None is respected. Fixes #2165
Member
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.
When using
map(attribute="...", default=None),make_attrgetterpreviously checkedif default is not None:, treatingdefault=Nonethe same as no default provided. Missing attributes therefore remainedUndefinedinstead of defaulting toNone, causingUndefinedErrorin strict environments (such as Ansible or when usingStrictUndefined).This PR:
missingsingleton fromjinja2.utilsas the default sentinel inmake_attrgetterandprepare_map.default=Noneevaluates toNone.groupby(avoiding the PyPy sorting regression in stale PR map and groupby filters accept explicitnoneas default value #2175).tests/test_filters.pyverifyingdefault=Noneunder standard andStrictUndefinedenvironments.Fixes #2165 (Supersedes #2175)