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

RFC: Robot Server should validate JSON protocols via schema def before executing #3250

Closed
IanLondon opened this issue Mar 22, 2019 · 0 comments · Fixed by #3318
Closed

RFC: Robot Server should validate JSON protocols via schema def before executing #3250

IanLondon opened this issue Mar 22, 2019 · 0 comments · Fixed by #3318
Labels
api Affects the `api` project RFC Software proposal ("request for comment")

Comments

@IanLondon
Copy link
Contributor

Acceptance Criteria

  • Uploading a JSON Protocol that does not validate under its corresponding schema should cause the Robot Server to throw an error explaining why validation failed.

Overview

Right now, the APIv1 and APIv2 executors are more permissive than the JSON schema. IMO this is a Bad Thing because it permits protocol creators to make out-of-spec JSON protocols. If a superuser makes a tool that creates JSON protocols which are invalid under the schema, and a version of the executor runs them just fine (perhaps by implicitly casting numbers to strings or visa-versa, or having other coincidental fallbacks), that superuser probably won't even be aware that their protocol creator is making invalid protocols. When users who have happily used that tool upgrade their robot and go to execute their protocols, they may get errors or unexpected behaviors.

Strongly encouraging schema consistency is very important for interoperability across our platform: between our own projects, as well as with third-party projects which we often have limited knowledge about. The schema is intended to enforce a common language across all JSON protocol creators and consumers, and we should take the opportunity to enforce it on protocol execution.

Implementation notes

Looks like jsonschema is the go-to JSON schema implementation in Python


Here's what "corresponding schema" means: JSON Protocol Schemas will be versioned with a single integer, but V1 and V2 are ill-specified (my fault!). A JSON protocol file has information about the schema version that is was written to comply with:

  • V1 protocols have "protocol-schema": "1.0.0" (or at least ^1). The schema def only specifies it should be a string, and the description says: A version string for the Opentrons JSON Protocol schema being used. "<major>.<minor>.<patch>.
  • V2 protocols have not yet been released, see feat(api): move-to-slot JSON protocol command #3242 . Similar to V1, it's a <major>.<minor>.<patch> string.
  • V3 protocols will drop the "protocol-schema" key and use whatever is agreed upon in Write new JSON schema for V3 #3110 (we shouldn't have to handle them in the context of this issue, until we're nearing a release of JSON Protocol V3 executor(s)). Future versions should follow this same convention.
@IanLondon IanLondon added api Affects the `api` project RFC Software proposal ("request for comment") labels Mar 22, 2019
IanLondon added a commit that referenced this issue Apr 9, 2019
* NOTE: this only works when you install the api as a developer or superuser, it will not affect
production robots

Closes #3250
IanLondon added a commit that referenced this issue Apr 9, 2019
* NOTE: this only works when you install the api as a developer or superuser, it will not affect
production robots

Closes #3250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the `api` project RFC Software proposal ("request for comment")
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant