You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inject only worked by coincidence of Pydantic coercion: now that we can have device singletons created without connect being called until appropriate, we can use the device instances as the default arguments to plans.
Acceptance Criteria
inject has been marked as deprecated
plans and stubs that currently make use of it in dodal have been replaced by a call to the device factory of the appropriate name called with (connect_immediately=False)
documentation has been updated to reflect this new recommended way of injecting default arguments into plans
plans in our plan repositories (mx-bluesky, i22-bluesky, etc.) have a pathway (issues or PRs) for migrating to the new method
inject was just lying to the type checking: blueapi maintains a dict of TypeReference[T] and when you register a plan knows that to convert from a str to a T involves fetching it from its internal context. It was found when we were looking at default args that this worked, and was intended as a temporary solution.
I'll be honest, I don't entirely know where in Pydantic the default argument was being converted to T: whether in creating the Model class for the PlanFunction or creating the instance of the model for the plan.
I've just had a thought that if it was the former (during creation of the model class for the plan function) that if you changed your blueapi config to load the plans prior to the devices it might fail in the way we've seen...
Using a @device_factory decorated non-connected device avoids lying to the type checking, the TypeReference then is only relevant to blueapi (where the context is and needing to handle str arguments from REST) and the implied but not guaranteed mapping of device.name to device instance is removed in favour of the factory function with the correct args.
Activity
d-perl commentedon Oct 21, 2024
Could you add some more details about this?
DiamondJoseph commentedon Oct 21, 2024
injectwas just lying to the type checking: blueapi maintains a dict ofTypeReference[T]and when you register a plan knows that to convert from astrto aTinvolves fetching it from its internal context. It was found when we were looking at default args that this worked, and was intended as a temporary solution.I'll be honest, I don't entirely know where in Pydantic the default argument was being converted to
T: whether in creating the Model class for the PlanFunction or creating the instance of the model for the plan.I've just had a thought that if it was the former (during creation of the model class for the plan function) that if you changed your blueapi config to load the plans prior to the devices it might fail in the way we've seen...
Using a
@device_factorydecorated non-connected device avoids lying to the type checking, theTypeReferencethen is only relevant to blueapi (where the context is and needing to handlestrarguments from REST) and the implied but not guaranteed mapping of device.name to device instance is removed in favour of the factory function with the correct args.