Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): Parse all RTP fields strictly to fix flakiness #15187

Merged
merged 4 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions api/src/opentrons/protocol_engine/types.py
SyntaxColoring marked this conversation as resolved.
Show resolved Hide resolved
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
Loading