fix: escape ${expression} in formatString description to prevent ADK KeyError#1409
Open
brucearctor wants to merge 1 commit into
Open
fix: escape ${expression} in formatString description to prevent ADK KeyError#1409brucearctor wants to merge 1 commit into
brucearctor wants to merge 1 commit into
Conversation
…KeyError
The formatString function description in basic_catalog.json contained
the literal text ${expression}, which the ADK's inject_session_state()
regex (r'{+[^{}]*}+') matched as a template variable. Since 'expression'
passes Python's str.isidentifier() check, the ADK attempted to look it
up in the session state dict and raised a KeyError when not found.
Changed ${expression} to ${<expression>} so that '<expression>' fails
the isidentifier() check, causing the ADK to skip it (returning the
match as-is). The other interpolation examples in the description
(${/absolute/path}, ${now()}, etc.) were already safe because they
contain characters (/, parentheses) that make them invalid identifiers.
Fixes google#1388
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.
Summary
Fixes #1388
The
formatStringfunction description inbasic_catalog.jsoncontained the literal text${expression}, which the ADK'sinject_session_state()matched as a template variable. Sinceexpressionpasses Python'sstr.isidentifier()check, the ADK raised aKeyErrorwhen it couldn't find it in the session state.Changes
Changed
${expression}→${<expression>}in theformatStringdescription for bothv0_9andv0_10catalog schemas.The angle brackets cause
<expression>to fail theisidentifier()check, so the ADK's_is_valid_state_name()returnsFalseand the match is returned as-is (line 108 ofinstructions_utils.py).Why only
${expression}was affectedThe other interpolation examples in the same description were already safe:
${/absolute/path}→/absolute/pathis not a valid identifier (contains/)${now()}→now()is not a valid identifier (contains())${relative/path}→relative/pathis not a valid identifier (contains/)Only
expressionwas a bare, valid Python identifier.Files changed
specification/v0_9/json/basic_catalog.jsonspecification/v0_10/json/basic_catalog.json