From ca83b25b03ae7dd42ec53463c29a06d7e0add00d Mon Sep 17 00:00:00 2001 From: amit lissack Date: Thu, 16 Apr 2020 10:04:50 -0400 Subject: [PATCH 1/4] updgrade fastapi to 0.54.1 --- robot-server/Pipfile | 2 +- robot-server/Pipfile.lock | 85 ++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/robot-server/Pipfile b/robot-server/Pipfile index c7d1ff2de89..455a9e496fb 100755 --- a/robot-server/Pipfile +++ b/robot-server/Pipfile @@ -18,7 +18,7 @@ requests = "*" [packages] uvicorn = "==0.11.3" -fastapi = "==0.49.0" +fastapi = "==0.54.1" python-multipart = "==0.0.5" aiohttp = "==3.4.4" python-dotenv = "*" diff --git a/robot-server/Pipfile.lock b/robot-server/Pipfile.lock index 4c27c923507..5a8aeacc5c9 100644 --- a/robot-server/Pipfile.lock +++ b/robot-server/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7818eaeb4c7ee643aff9bc6cf2346a08a86362078bf34d66fe15493e0ee190ae" + "sha256": "612df776739fe8fc7cd5471e83e0f261f3f445f360973a593ca0fcbac513a1ce" }, "pipfile-spec": 6, "requires": { @@ -74,11 +74,11 @@ }, "fastapi": { "hashes": [ - "sha256:717dbd2871c270970c70406ef4e550c3504525a7941df817f3a1318de0857c13", - "sha256:c9296e05a011a53c5b4f0a12f06c261b95b7199685b3af986486e41a27545081" + "sha256:1ee9a49f28d510b62b3b51a9452b274853bfc9c5d4b947ed054366e2d49f9efa", + "sha256:72f40f47e5235cb5cbbad1d4f97932ede6059290c07e12e9784028dcd1063d28" ], "index": "pypi", - "version": "==0.49.0" + "version": "==0.54.1" }, "h11": { "hashes": [ @@ -177,9 +177,10 @@ }, "starlette": { "hashes": [ - "sha256:c2ac9a42e0e0328ad20fe444115ac5e3760c1ee2ac1ff8cdb5ec915c4a453411" + "sha256:6169ee78ded501095d1dda7b141a1dc9f9934d37ad23196e180150ace2c6449b", + "sha256:a9bb130fa7aa736eda8a814b6ceb85ccf7a209ed53843d0d61e246b380afa10f" ], - "version": "==0.12.9" + "version": "==0.13.2" }, "uvicorn": { "hashes": [ @@ -333,39 +334,39 @@ }, "coverage": { "hashes": [ - "sha256:03f630aba2b9b0d69871c2e8d23a69b7fe94a1e2f5f10df5049c0df99db639a0", - "sha256:046a1a742e66d065d16fb564a26c2a15867f17695e7f3d358d7b1ad8a61bca30", - "sha256:0a907199566269e1cfa304325cc3b45c72ae341fbb3253ddde19fa820ded7a8b", - "sha256:165a48268bfb5a77e2d9dbb80de7ea917332a79c7adb747bd005b3a07ff8caf0", - "sha256:1b60a95fc995649464e0cd48cecc8288bac5f4198f21d04b8229dc4097d76823", - "sha256:1f66cf263ec77af5b8fe14ef14c5e46e2eb4a795ac495ad7c03adc72ae43fafe", - "sha256:2e08c32cbede4a29e2a701822291ae2bc9b5220a971bba9d1e7615312efd3037", - "sha256:3844c3dab800ca8536f75ae89f3cf566848a3eb2af4d9f7b1103b4f4f7a5dad6", - "sha256:408ce64078398b2ee2ec08199ea3fcf382828d2f8a19c5a5ba2946fe5ddc6c31", - "sha256:443be7602c790960b9514567917af538cac7807a7c0c0727c4d2bbd4014920fd", - "sha256:4482f69e0701139d0f2c44f3c395d1d1d37abd81bfafbf9b6efbe2542679d892", - "sha256:4a8a259bf990044351baf69d3b23e575699dd60b18460c71e81dc565f5819ac1", - "sha256:513e6526e0082c59a984448f4104c9bf346c2da9961779ede1fc458e8e8a1f78", - "sha256:5f587dfd83cb669933186661a351ad6fc7166273bc3e3a1531ec5c783d997aac", - "sha256:62061e87071497951155cbccee487980524d7abea647a1b2a6eb6b9647df9006", - "sha256:641e329e7f2c01531c45c687efcec8aeca2a78a4ff26d49184dce3d53fc35014", - "sha256:65a7e00c00472cd0f59ae09d2fb8a8aaae7f4a0cf54b2b74f3138d9f9ceb9cb2", - "sha256:6ad6ca45e9e92c05295f638e78cd42bfaaf8ee07878c9ed73e93190b26c125f7", - "sha256:73aa6e86034dad9f00f4bbf5a666a889d17d79db73bc5af04abd6c20a014d9c8", - "sha256:7c9762f80a25d8d0e4ab3cb1af5d9dffbddb3ee5d21c43e3474c84bf5ff941f7", - "sha256:85596aa5d9aac1bf39fe39d9fa1051b0f00823982a1de5766e35d495b4a36ca9", - "sha256:86a0ea78fd851b313b2e712266f663e13b6bc78c2fb260b079e8b67d970474b1", - "sha256:8a620767b8209f3446197c0e29ba895d75a1e272a36af0786ec70fe7834e4307", - "sha256:922fb9ef2c67c3ab20e22948dcfd783397e4c043a5c5fa5ff5e9df5529074b0a", - "sha256:9fad78c13e71546a76c2f8789623eec8e499f8d2d799f4b4547162ce0a4df435", - "sha256:a37c6233b28e5bc340054cf6170e7090a4e85069513320275a4dc929144dccf0", - "sha256:c3fc325ce4cbf902d05a80daa47b645d07e796a80682c1c5800d6ac5045193e5", - "sha256:cda33311cb9fb9323958a69499a667bd728a39a7aa4718d7622597a44c4f1441", - "sha256:db1d4e38c9b15be1521722e946ee24f6db95b189d1447fa9ff18dd16ba89f732", - "sha256:eda55e6e9ea258f5e4add23bcf33dc53b2c319e70806e180aecbff8d90ea24de", - "sha256:f372cdbb240e09ee855735b9d85e7f50730dcfb6296b74b95a3e5dea0615c4c1" - ], - "version": "==5.0.4" + "sha256:00f1d23f4336efc3b311ed0d807feb45098fc86dee1ca13b3d6768cdab187c8a", + "sha256:01333e1bd22c59713ba8a79f088b3955946e293114479bbfc2e37d522be03355", + "sha256:0cb4be7e784dcdc050fc58ef05b71aa8e89b7e6636b99967fadbdba694cf2b65", + "sha256:0e61d9803d5851849c24f78227939c701ced6704f337cad0a91e0972c51c1ee7", + "sha256:1601e480b9b99697a570cea7ef749e88123c04b92d84cedaa01e117436b4a0a9", + "sha256:2742c7515b9eb368718cd091bad1a1b44135cc72468c731302b3d641895b83d1", + "sha256:2d27a3f742c98e5c6b461ee6ef7287400a1956c11421eb574d843d9ec1f772f0", + "sha256:402e1744733df483b93abbf209283898e9f0d67470707e3c7516d84f48524f55", + "sha256:5c542d1e62eece33c306d66fe0a5c4f7f7b3c08fecc46ead86d7916684b36d6c", + "sha256:5f2294dbf7875b991c381e3d5af2bcc3494d836affa52b809c91697449d0eda6", + "sha256:6402bd2fdedabbdb63a316308142597534ea8e1895f4e7d8bf7476c5e8751fef", + "sha256:66460ab1599d3cf894bb6baee8c684788819b71a5dc1e8fa2ecc152e5d752019", + "sha256:782caea581a6e9ff75eccda79287daefd1d2631cc09d642b6ee2d6da21fc0a4e", + "sha256:79a3cfd6346ce6c13145731d39db47b7a7b859c0272f02cdb89a3bdcbae233a0", + "sha256:7a5bdad4edec57b5fb8dae7d3ee58622d626fd3a0be0dfceda162a7035885ecf", + "sha256:8fa0cbc7ecad630e5b0f4f35b0f6ad419246b02bc750de7ac66db92667996d24", + "sha256:a027ef0492ede1e03a8054e3c37b8def89a1e3c471482e9f046906ba4f2aafd2", + "sha256:a3f3654d5734a3ece152636aad89f58afc9213c6520062db3978239db122f03c", + "sha256:a82b92b04a23d3c8a581fc049228bafde988abacba397d57ce95fe95e0338ab4", + "sha256:acf3763ed01af8410fc36afea23707d4ea58ba7e86a8ee915dfb9ceff9ef69d0", + "sha256:adeb4c5b608574a3d647011af36f7586811a2c1197c861aedb548dd2453b41cd", + "sha256:b83835506dfc185a319031cf853fa4bb1b3974b1f913f5bb1a0f3d98bdcded04", + "sha256:bb28a7245de68bf29f6fb199545d072d1036a1917dca17a1e75bbb919e14ee8e", + "sha256:bf9cb9a9fd8891e7efd2d44deb24b86d647394b9705b744ff6f8261e6f29a730", + "sha256:c317eaf5ff46a34305b202e73404f55f7389ef834b8dbf4da09b9b9b37f76dd2", + "sha256:dbe8c6ae7534b5b024296464f387d57c13caa942f6d8e6e0346f27e509f0f768", + "sha256:de807ae933cfb7f0c7d9d981a053772452217df2bf38e7e6267c9cbf9545a796", + "sha256:dead2ddede4c7ba6cb3a721870f5141c97dc7d85a079edb4bd8d88c3ad5b20c7", + "sha256:dec5202bfe6f672d4511086e125db035a52b00f1648d6407cc8e526912c0353a", + "sha256:e1ea316102ea1e1770724db01998d1603ed921c54a86a2efcb03428d5417e489", + "sha256:f90bfc4ad18450c80b024036eaf91e4a246ae287701aaa88eaebebf150868052" + ], + "version": "==5.1" }, "idna": { "hashes": [ @@ -515,10 +516,10 @@ }, "pyflakes": { "hashes": [ - "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0", - "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2" + "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92", + "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8" ], - "version": "==2.1.1" + "version": "==2.2.0" }, "pylama": { "hashes": [ From 769b8a3a07557688bc8c0659263f7fe6b8ad53f5 Mon Sep 17 00:00:00 2001 From: amit lissack Date: Thu, 16 Apr 2020 10:05:52 -0400 Subject: [PATCH 2/4] remove workarounds to deal with bugs in fastapi --- .../robot_server/service/routers/settings.py | 20 +++------- robot-server/tests/service/rpc/test_server.py | 37 ++----------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/robot-server/robot_server/service/routers/settings.py b/robot-server/robot_server/service/routers/settings.py index 0578f5407c8..d385165ed4e 100644 --- a/robot-server/robot_server/service/routers/settings.py +++ b/robot-server/robot_server/service/routers/settings.py @@ -1,5 +1,5 @@ import logging -from typing import Union, Dict +from typing import Dict from starlette import status from fastapi import APIRouter, Depends @@ -182,16 +182,14 @@ async def get_robot_settings( response_model=MultiPipetteSettings, response_model_by_alias=True, response_model_exclude_unset=True) -async def get_pipette_settings() -> Union[Dict, MultiPipetteSettings]: +async def get_pipette_settings() -> MultiPipetteSettings: res = {} for pipette_id in pipette_config.known_pipettes(): # Have to convert to dict using by_alias due to bug in fastapi res[pipette_id] = _pipette_settings_from_config( pipette_config, pipette_id, - ).dict(by_alias=True, - exclude_unset=True) - + ) return res @@ -201,16 +199,12 @@ async def get_pipette_settings() -> Union[Dict, MultiPipetteSettings]: response_model_by_alias=True, response_model_exclude_unset=True, responses={status.HTTP_404_NOT_FOUND: {"model": V1BasicResponse}}) -async def get_pipette_setting(pipette_id: str) -> Union[Dict, PipetteSettings]: +async def get_pipette_setting(pipette_id: str) -> PipetteSettings: if pipette_id not in pipette_config.known_pipettes(): raise V1HandlerError(status_code=status.HTTP_404_NOT_FOUND, message=f'{pipette_id} is not a valid pipette id') - # Have to convert to dict using by_alias due to bug in fastapi r = _pipette_settings_from_config( pipette_config, pipette_id - ).dict( - by_alias=True, - exclude_unset=True, ) return r @@ -228,7 +222,7 @@ async def get_pipette_setting(pipette_id: str) -> Union[Dict, PipetteSettings]: async def patch_pipette_setting( pipette_id: str, settings_update: PipetteSettingsUpdate) \ - -> Union[Dict, PipetteSettings]: + -> PipetteSettings: # Convert fields to dict of field name to value fields = settings_update.setting_fields or {} @@ -241,12 +235,8 @@ async def patch_pipette_setting( raise V1HandlerError( status_code=status.HTTP_412_PRECONDITION_FAILED, message=str(e)) - # Have to convert to dict using by_alias due to bug in fastapi r = _pipette_settings_from_config( pipette_config, pipette_id - ).dict( - by_alias=True, - exclude_unset=True, ) return r diff --git a/robot-server/tests/service/rpc/test_server.py b/robot-server/tests/service/rpc/test_server.py index 3842dcbfaa5..f466cc365f8 100755 --- a/robot-server/tests/service/rpc/test_server.py +++ b/robot-server/tests/service/rpc/test_server.py @@ -25,38 +25,7 @@ class Session(typing.NamedTuple): @pytest.fixture -def rpc_client(): - """Create an starlette TestClient to communicate with rpc""" - - # We should be able to just use api_client fixture but can't due to a bug - # in fastapi. - # Fastapi does not allow overriding dependencies on websocket endpoints. - # See https://github.com/tiangolo/fastapi/issues/998 - # We've submitted a PR to fix this: - # https://github.com/tiangolo/fastapi/pull/1122 but in the meantime we - # have to hack monkey patch a solution - app = FastAPI() - - def add_api_websocket_route( - self, path: str, endpoint: typing.Callable, name: str = None - ) -> None: - route = APIWebSocketRoute( - path, - endpoint=endpoint, - name=name, - dependency_overrides_provider=self.dependency_overrides_provider, - ) - self.routes.append(route) - - APIRouter.add_api_websocket_route = add_api_websocket_route # type: ignore - - app.include_router(router) - - return TestClient(app) - - -@pytest.fixture -def session(loop, rpc_client, request) -> Session: +def session(loop, api_client, request) -> Session: """ Create testing session. Tests using this fixture are expected to have @pytest.mark.parametrize('root', [value]) decorator set. @@ -74,10 +43,10 @@ async def get_server(): return _internal_server # Override the RPC server dependency - rpc_client.app.dependency_overrides[get_rpc_server] = get_server + api_client.app.dependency_overrides[get_rpc_server] = get_server # Connect - socket = rpc_client.websocket_connect("/") + socket = api_client.websocket_connect("/") token = str(uuid()) def call(**kwargs): From 06223d21194a45689574b92acc0d95726eef6f15 Mon Sep 17 00:00:00 2001 From: amit lissack Date: Thu, 16 Apr 2020 10:27:19 -0400 Subject: [PATCH 3/4] lint errors --- robot-server/tests/service/rpc/test_server.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/robot-server/tests/service/rpc/test_server.py b/robot-server/tests/service/rpc/test_server.py index f466cc365f8..b5a2dfad1fb 100755 --- a/robot-server/tests/service/rpc/test_server.py +++ b/robot-server/tests/service/rpc/test_server.py @@ -6,15 +6,12 @@ from threading import Event, Semaphore from uuid import uuid4 as uuid -from fastapi.routing import APIWebSocketRoute -from starlette.testclient import WebSocketTestSession, TestClient -from fastapi import FastAPI, APIRouter +from starlette.testclient import WebSocketTestSession from opentrons.protocol_api.execute import ExceptionInProtocolError from robot_server.service.dependencies import get_rpc_server from robot_server.service.rpc import rpc -from robot_server.service.routers.rpc import router class Session(typing.NamedTuple): From 5a0983792376a7e9104ac4cc7680df638ad34946 Mon Sep 17 00:00:00 2001 From: amit lissack Date: Thu, 16 Apr 2020 10:27:53 -0400 Subject: [PATCH 4/4] select BR2_PACKAGE_PYTHON_DOTENV package --- robot-server/Config.in | 1 + 1 file changed, 1 insertion(+) diff --git a/robot-server/Config.in b/robot-server/Config.in index 257c0629e44..5b75aa30c6a 100644 --- a/robot-server/Config.in +++ b/robot-server/Config.in @@ -5,6 +5,7 @@ config BR2_PACKAGE_PYTHON_OPENTRONS_ROBOT_SERVER select BR2_PACKAGE_PYTHON_FASTAPI # runtime select BR2_PACKAGE_PYTHON_UVICORN # runtime select BR2_PACKAGE_PYTHON_MULTIPART # runtime + select BR2_PACKAGE_PYTHON_DOTENV # runtime help Opentrons HTTP server. Controls an OT2 robot.