Name the missing key and suggest safe access in collection key-not-found errors - #9664
Open
jhonabreul wants to merge 1 commit into
Open
Name the missing key and suggest safe access in collection key-not-found errors#9664jhonabreul wants to merge 1 commit into
jhonabreul wants to merge 1 commit into
Conversation
…und errors Slice/DataDictionary/Securities/Portfolio key-not-found messages now share one template that names the key and appends a language-aware guard suggestion (data.get(symbol) / 'if symbol in data:' for Python, TryGetValue/ContainsKey for C#). The Python KeyError interpreter reads the key from the exception args so object keys (e.g. Symbol on a plain dict) no longer render blank, and a new AttributeError interpreter explains wrong-bar-type access such as QuoteBar.volume. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jhonabreul
marked this pull request as ready for review
August 12, 2026 18:40
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.
Description
Key-not-found errors from symbol-keyed collections did not always name the missing key or say how to avoid the crash. Non-string keys (e.g. a
Symbol) rendered blank, and wrong-bar-type access got an unhelpful Python suggestion:The changes:
Slice/DataDictionaryindexer errors now share a single template: it names the key, renders friendly generic type names, and suggests the safe-access idiom per language (data.get(symbol)/if symbol in data:for Python,TryGetValue/ContainsKeyfor C#).Securities/Portfoliomissing-symbol errors append the same suggestion.KeyErrorPythonExceptionInterpreterreads the key from the exception value instead of parsing the message, so object keys are named instead of rendering blank.AttributeErrorPythonExceptionInterpreter:QuoteBar.volumepoints atdata.bars.get(symbol), andTradeBarbid/ask access points atdata.quote_bars.get(symbol). Other AttributeErrors are untouched.Audited, no change needed:
.get(symbol)andinalready work across all these collections.Related Issue
N/A
Motivation and Context
These are among the most frequent runtime crashes in Python algorithms. When the message names the key and the guard idiom, the failure is fixable in one shot.
Requires Documentation Change
No.
How Has This Been Tested?
KeyErrorPythonExceptionInterpreterTests: new tests for string keys and object keys (reproduces the blank-key rendering with aSymbol-keyed dict).AttributeErrorPythonExceptionInterpreterTests: asserts both hints and that unrelated AttributeErrors are left alone.SliceTests/SecurityManagerTests: assert the C# and Python message variants.Tests.Common.Exceptions,SliceTests,SecurityManagerTests,ExtendedDictionaryTests,OrderTicketTests,SecurityPortfolioManagerTests(333 passed, 0 failed).Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>