Throw clear error when add_data first argument is not a custom data class#9473
Merged
Martin-Molinero merged 2 commits intoMay 12, 2026
Merged
Conversation
…ent from Python
Calls like self.add_data("VIX", Resolution.DAILY) routed through CreateType, which
silently built a dynamic assembly named after the string and returned a fake type
whose activator factory tried to invoke the str like a function. The downstream
'str' object is not callable PythonException surfaced confusingly (and could
manifest as an apparent hang depending on where it was caught), making the actual
mistake hard to diagnose.
Validate the PyObject up front via TryCreateType in the AddData(PyObject, ...)
entry points and throw an ArgumentException pointing the user at AddEquity /
AddForex / etc. when the argument is not a custom data class.
Use only two alternative methods as examples, as we don't need an exhaustive list.
Martin-Molinero
approved these changes
May 12, 2026
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
Calls like
self.add_data("VIX", Resolution.DAILY)(passing a string where a custom data class is expected) used to fall intoExtensions.CreateType, which silently built a dynamic assembly named after the string and returned a fakeTypewhosePythonActivator.Factorytried toInvoke()the str like a function. The downstream'str' object is not callablePythonExceptionsurfaced confusingly and, depending on where the engine caught it during initialization, could appear to the user as a hang.This PR validates the
PyObjectup front in theAddData(PyObject, ...)entry points using the existingTryCreateTypehelper and throws anArgumentExceptionthat points the user atAddEquity/AddForex/ etc. when the argument is not a custom data class.Related Issue
N/A — no public issue was filed for this.
Motivation and Context
A common user mistake (treating
add_datalikeadd_equity) produced a confusing failure mode ('str' object is not callable/ apparent hang) instead of a clear, actionable error.Requires Documentation Change
No.
How Has This Been Tested?
Added
AlgorithmAddDataTests.AddDataWithStringAsTypeArgumentThrowsClearError. The test was first run against the unfixed code to confirm the original symptom (PythonException: 'str' object is not callablethrown fromPythonActivator.FactoryviaGetBaseDataInstance), then re-run against the fixed code to confirm anArgumentExceptionmentioningAddDataandAddEquityis now thrown. The pre-existingPythonCustomDataTypes_AreAddedToSubscriptions_Successfully,PythonCustomDataTypes_AreAddedToConsolidator_Successfully, andAddingInvalidDataTypeThrowstests still pass.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>