fix(api): Fix Pydantic error when parsing commands that did not succeed #17264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
robot-server sometimes stores, in its database, run commands that do not have a
result
. For example, if a command failed, it has anerror
instead of aresult
.After the recent Pydantic v1->v2 upgrade, parsing these commands was broken for about 1/3rd of our command types. The server would raise a 500 error. Their Pydantic models were defined like:
In Pydantic v1, that parses JSON where
result
isnull
or omitted, but in Pydantic v2, it only parses JSON whereresult
isnull
. We need to change it to:Addresses RQA-3853, I think.
Test Plan and Hands on Testing
GET /runs/.../commands/...
request that fails with a 500 error without this PR, and make sure it succeeds with this PR.Review requests
I made this change by running
bump-pydantic
onapi/src/opentrons/protocol_engine
. Double-check my work to make sure no changes snuck in outside of what I've described above.Risk assessment
Low.