Skip to content

Refactor: Combine functionality of Plan and Plan model #1728

Closed as not planned

Description

@abbiemery

Linked to the same issue for devices #1725

The distinction between the bluesky type Plan and the api model
PlanModel was created to ensure a seperation of concerns between the
plans that the context uses for running plans and the serializable
representation required for the rest api. However in practice this 'Plan'
is already as a model as the plan functions are stored with it. It does
not provide a useful distinction and adds an extra model that we don't
need.

We can instead unify to

class BlueapiPlan(BlueapiBaseModel):
    """
    A plan that can be run
    """

    name: str = Field(description="Referenceable name of the plan")
    description: str | None = Field(
        description="Description/docstring of the plan", default=None
    )
    model: type[BaseModel] = Field(
        description="Validation model of the parameters for the plan"
    )

    def to_model(self) -> dict[str, Any]:
        return {
            "name": self.name,
            "parameter_schema": self.model.model_json_schema(),
            "description": self.description,
        }

Where the to_model does the logic in the current PlanModel for
creating it's self from the current bluesky_type.Plan for rest.

@classmethod
    def from_plan(cls, plan: Plan) -> "PlanModel":
        return cls(
            name=plan.name,
            schema=plan.model.model_json_schema(),
            description=plan.description,
        )

There are pro's and cons to the naming of this class. I have gone with
BlueapiPlan to make it distinct from both the raw plan and the model
for human readability reasons. This will help with unification with the
device refactor and we can change it later if it is contentious.

Acceptance Criteria

  • The PlanModel in model is removed and the logic for creating it is
    stored with the plan in the context.

Activity

  1. tpoliaw commented on Nov 9, 2026

    @tpoliaw
    Contributor

    From discussions around trying to implement this, we should keep the Plan and PlanModel types separate. They serve different purposes and lets us separate the REST interface and client code from the internals of the server. Expanding the current Plan type still lets us improve the plan handling in the context.

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