Skip to content

Commit 9b8eafc

Browse files
shlokaminSyntaxColoringecormanysanni-t
authored
fix(api): Parse all RTP fields strictly to fix flakiness (#15187) (#15536)
closes https://opentrons.atlassian.net/browse/RESC-287 --------- Co-authored-by: Max Marrone <[email protected]> Co-authored-by: Edward Cormany <[email protected]> Co-authored-by: Sanniti Pimpley <[email protected]>
1 parent 1193c29 commit 9b8eafc

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

api/release-notes.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Welcome to the v7.4.0 release of the Opentrons robot software!
1212

1313
This release adds support for the [Opentrons Flex HEPA/UV Module](https://opentrons.com/products/opentrons-flex-hepa-uv-module).
1414

15+
### Bug Fixes
16+
17+
- Fixed certain string runtime parameter values being misinterpreted as an incorrect type.
1518
---
1619

1720
## Opentrons Robot Software Changes in 7.3.1

api/src/opentrons/protocol_engine/types.py

+28-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
from datetime import datetime
55
from enum import Enum
66
from dataclasses import dataclass
7-
from pydantic import BaseModel, Field, validator
7+
from pydantic import (
8+
BaseModel,
9+
Field,
10+
StrictBool,
11+
StrictFloat,
12+
StrictInt,
13+
StrictStr,
14+
validator,
15+
)
816
from typing import Optional, Union, List, Dict, Any, NamedTuple, Tuple, FrozenSet
917
from typing_extensions import Literal, TypeGuard
1018

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

880-
displayName: str = Field(..., description="Display string for the parameter.")
881-
variableName: str = Field(..., description="Python variable name of the parameter.")
882-
description: Optional[str] = Field(
888+
displayName: StrictStr = Field(..., description="Display string for the parameter.")
889+
variableName: StrictStr = Field(
890+
..., description="Python variable name of the parameter."
891+
)
892+
description: Optional[StrictStr] = Field(
883893
None, description="Detailed description of the parameter."
884894
)
885-
suffix: Optional[str] = Field(
895+
suffix: Optional[StrictStr] = Field(
886896
None,
887897
description="Units (like mL, mm/sec, etc) or a custom suffix for the parameter.",
888898
)
@@ -894,17 +904,17 @@ class NumberParameter(RTPBase):
894904
type: Literal["int", "float"] = Field(
895905
..., description="String specifying whether the number is an int or float type."
896906
)
897-
min: float = Field(
907+
min: Union[StrictInt, StrictFloat] = Field(
898908
..., description="Minimum value that the number param is allowed to have."
899909
)
900-
max: float = Field(
910+
max: Union[StrictInt, StrictFloat] = Field(
901911
..., description="Maximum value that the number param is allowed to have."
902912
)
903-
value: float = Field(
913+
value: Union[StrictInt, StrictFloat] = Field(
904914
...,
905915
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
906916
)
907-
default: float = Field(
917+
default: Union[StrictInt, StrictFloat] = Field(
908918
...,
909919
description="Default value of the parameter, to be used when there is no client-specified value.",
910920
)
@@ -916,11 +926,11 @@ class BooleanParameter(RTPBase):
916926
type: Literal["bool"] = Field(
917927
default="bool", description="String specifying the type of this parameter"
918928
)
919-
value: bool = Field(
929+
value: StrictBool = Field(
920930
...,
921931
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
922932
)
923-
default: bool = Field(
933+
default: StrictBool = Field(
924934
...,
925935
description="Default value of the parameter, to be used when there is no client-specified value.",
926936
)
@@ -929,8 +939,10 @@ class BooleanParameter(RTPBase):
929939
class EnumChoice(BaseModel):
930940
"""Components of choices used in RTP Enum Parameters."""
931941

932-
displayName: str = Field(..., description="Display string for the param's choice.")
933-
value: Union[float, str] = Field(
942+
displayName: StrictStr = Field(
943+
..., description="Display string for the param's choice."
944+
)
945+
value: Union[StrictInt, StrictFloat, StrictStr] = Field(
934946
..., description="Enum value of the param's choice."
935947
)
936948

@@ -945,11 +957,11 @@ class EnumParameter(RTPBase):
945957
choices: List[EnumChoice] = Field(
946958
..., description="List of valid choices for this parameter."
947959
)
948-
value: Union[float, str] = Field(
960+
value: Union[StrictInt, StrictFloat, StrictStr] = Field(
949961
...,
950962
description="The value assigned to the parameter; if not supplied by the client, will be assigned the default value.",
951963
)
952-
default: Union[float, str] = Field(
964+
default: Union[StrictInt, StrictFloat, StrictStr] = Field(
953965
...,
954966
description="Default value of the parameter, to be used when there is no client-specified value.",
955967
)
@@ -958,5 +970,5 @@ class EnumParameter(RTPBase):
958970
RunTimeParameter = Union[NumberParameter, EnumParameter, BooleanParameter]
959971

960972
RunTimeParamValuesType = Dict[
961-
str, Union[float, bool, str]
973+
StrictStr, Union[StrictInt, StrictFloat, StrictBool, StrictStr]
962974
] # update value types as more RTP types are added

0 commit comments

Comments
 (0)