Skip to content

Deprecate inject method #845

Closed
Closed

Description

@DiamondJoseph

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

Activity

  1. d-perl commented on Oct 21, 2024

    @d-perl
    Contributor

    inject only worked by coincidence of Pydantic coercion

    Could you add some more details about this?

  2. DiamondJoseph commented on Oct 21, 2024

    @DiamondJoseph
    ContributorAuthor

    Could you add some more details about this?

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions