Skip to content

Commit

Permalink
fix(api): Parse all RTP fields strictly to fix flakiness (#15187)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring authored and Carlos-fernandez committed Jun 3, 2024
1 parent de1a346 commit d905d07
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions api/src/opentrons/protocol_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
from datetime import datetime
from enum import Enum
from dataclasses import dataclass
from pydantic import BaseModel, Field, validator
from pydantic import (
BaseModel,
Field,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
validator,
)
from typing import Optional, Union, List, Dict, Any, NamedTuple, Tuple, FrozenSet
from typing_extensions import Literal, TypeGuard

Expand Down Expand Up @@ -877,12 +885,14 @@ def from_hw_state(cls, state: HwTipStateType) -> "TipPresenceStatus":
class RTPBase(BaseModel):
"""Parameters defined in a protocol."""

displayName: str = Field(..., description="Display string for the parameter.")
variableName: str = Field(..., description="Python variable name of the parameter.")
description: Optional[str] = Field(
displayName: StrictStr = Field(..., description="Display string for the parameter.")
variableName: StrictStr = Field(
..., description="Python variable name of the parameter."
)
description: Optional[StrictStr] = Field(
None, description="Detailed description of the parameter."
)
suffix: Optional[str] = Field(
suffix: Optional[StrictStr] = Field(
None,
description="Units (like mL, mm/sec, etc) or a custom suffix for the parameter.",
)
Expand All @@ -894,17 +904,17 @@ class NumberParameter(RTPBase):
type: Literal["int", "float"] = Field(
..., description="String specifying whether the number is an int or float type."
)
min: float = Field(
min: Union[StrictInt, StrictFloat] = Field(
..., description="Minimum value that the number param is allowed to have."
)
max: float = Field(
max: Union[StrictInt, StrictFloat] = Field(
..., description="Maximum value that the number param is allowed to have."
)
value: float = Field(
value: Union[StrictInt, StrictFloat] = Field(
...,
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
)
default: float = Field(
default: Union[StrictInt, StrictFloat] = Field(
...,
description="Default value of the parameter, to be used when there is no client-specified value.",
)
Expand All @@ -916,11 +926,11 @@ class BooleanParameter(RTPBase):
type: Literal["bool"] = Field(
default="bool", description="String specifying the type of this parameter"
)
value: bool = Field(
value: StrictBool = Field(
...,
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
)
default: bool = Field(
default: StrictBool = Field(
...,
description="Default value of the parameter, to be used when there is no client-specified value.",
)
Expand All @@ -929,8 +939,10 @@ class BooleanParameter(RTPBase):
class EnumChoice(BaseModel):
"""Components of choices used in RTP Enum Parameters."""

displayName: str = Field(..., description="Display string for the param's choice.")
value: Union[float, str] = Field(
displayName: StrictStr = Field(
..., description="Display string for the param's choice."
)
value: Union[StrictInt, StrictFloat, StrictStr] = Field(
..., description="Enum value of the param's choice."
)

Expand All @@ -945,11 +957,11 @@ class EnumParameter(RTPBase):
choices: List[EnumChoice] = Field(
..., description="List of valid choices for this parameter."
)
value: Union[float, str] = Field(
value: Union[StrictInt, StrictFloat, StrictStr] = Field(
...,
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
)
default: Union[float, str] = Field(
default: Union[StrictInt, StrictFloat, StrictStr] = Field(
...,
description="Default value of the parameter, to be used when there is no client-specified value.",
)
Expand All @@ -958,5 +970,5 @@ class EnumParameter(RTPBase):
RunTimeParameter = Union[NumberParameter, EnumParameter, BooleanParameter]

RunTimeParamValuesType = Dict[
str, Union[float, bool, str]
StrictStr, Union[StrictInt, StrictFloat, StrictBool, StrictStr]
] # update value types as more RTP types are added

0 comments on commit d905d07

Please sign in to comment.