-
Notifications
You must be signed in to change notification settings - Fork 178
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
Conversation
I have no idea why this is the case, but adding this import changes the result of: pipenv run python -c 'from robot_server.protocols.analysis_models import AnalysisRequest; print(AnalysisRequest(runTimeParameterValues={"vol": 123, "dry_run": True, "mount": "left"}))'
This reverts commit c90840d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for fixing this
@ncdiehl11 verified that there are no app-side changes for this |
Thank you both for the quick reviews and tests! This was an adventure. 🗺️ [Edit] Oh, is it correct for this to merge into |
Edge please. Not enough time to test before the release. Especially with possible DB side effects. I need to add type assertions on all the RTP at runtime in my snapshot test. On my list now. |
…5536) 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]>
Overview
Closes AUTH-401.
Changelog
As described in AUTH-401, there were two problems:
true
intoUnion[float, bool, str]
could return1.0
instead ofTrue
. This is because of Pydantic's type coercion.The solution to both of these problems is to disable Pydantic's type coercion. That solves the first problem for obvious reasons. It solves the second problem because, when parsing something like a
Union[float, bool, str]
, there will no longer be any "ties" that Pydantic needs to break by usingUnion
order.(In my opinion, this is also a good practice in general, and we should do it for everything going forward.)
For all fields in all run-time parameter models, change
int
toStrictInt
,str
toStrictStr
,bool
toStrictBool
, andfloat
toUnion[StrictInt, StrictFloat]
. That lastUnion
is because numbers like123
, without a decimal point, do not parse intoStrictFloat
.Test plan
pipenv run pytest tests/protocols/test_protocols_router.py::test_create_protocol_analyses_with_same_rtp_values
on commits c90840d and 65a57e8. It will fail on the first one (before the fix) and succeed on the second one (after the fix).Review requests
Are there any fields or models that I missed?
Also see risk assessment.
Risk assessment
Medium?
Changes like this can break the database if we've been accidentally storing stuff wrongly, like if we've been storing
"1.23"
where we meant to store1.23
and this PR changes that field fromfloat
toStrictFloat
.There's also some risk that the frontend has had bugs where it sends the wrong types, but the server-side type coercion has been masking them. The server will return
422
errors now.I'll defer to AUTH people for their assessment of how likely we are to have problems like these, and how much manual testing we need to do to be confident.