Repository navigation
fix: Ignore NameError when introspecting plan functions - #1575
Merged
Merged
Conversation
tpoliaw
force-pushed
the
field-type-hints
branch
from
June 26, 2026 13:15
9bf99b0 to
4bf2f92
Compare
abbiemery
requested changes
Jun 26, 2026
abbiemery
left a comment
Contributor
There was a problem hiding this comment.
Can you elaborate on the comment re pydantic.Field and jsonValue so we don't have to discover this again
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1575 +/- ##
=======================================
Coverage 95.93% 95.93%
=======================================
Files 44 44
Lines 3269 3269
=======================================
Hits 3136 3136
Misses 133 133 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
When getting type hints to determine if a function is a plan, a
`NameError` can be raised (specifically when checking `pydantic.Field`
in this case) and the context loading crashes. Ignoring the error in the
same way that we ignore `TypeError` allows us to ignore broken types.
As we are only interested in specific return types (`Generator`) this
shouldn't affect which functions are treated as plans.
Specific symptoms/causes:
In pydantic `Field` has an argument with a type hint of (via an alias or
two) `JsonValue`. This is defined as a recursive alias
JsonValue: TypeAlias = Union[int, float, str, bool, None, list['JsonValue'], 'JsonDict']
JsonDict: TypeAlias = dict[str, JsonValue]
when `get_type_hints` is called on `Field` a `NameError` is raised.
This can be seen in a python repl
>>> from typing import get_type_hints
>>> from pydantic import Field
>>> get_type_hints(Field)
Traceback (most recent call last):
...
NameError: name 'JsonValue' is not defined
In blueapi, this is a problem if any module included via a PlanSource
has `Field` as a top level object.
tpoliaw
force-pushed
the
field-type-hints
branch
from
June 26, 2026 13:41
4bf2f92 to
cb6c788
Compare
abbiemery
approved these changes
Jun 26, 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.
fix: Ignore NameError when introspecting plan functions
When getting type hints to determine if a function is a plan, a
NameErrorcan be raised (specifically when checkingpydantic.Fieldin this case) and the context loading crashes. Ignoring the error in the
same way that we ignore
TypeErrorallows us to ignore broken types.As we are only interested in specific return types (
Generator) thisshouldn't affect which functions are treated as plans.
Specific symptoms/causes:
In pydantic
Fieldhas an argument with a type hint of (via an alias ortwo)
JsonValue. This is defined as a recursive aliaswhen
get_type_hintsis called onFieldaNameErroris raised.This can be seen in a python repl without any blueapi related code
In blueapi, this is a problem if any module included via a PlanSource
has
Fieldas a top level object.