From f95c13f203377a93d821d96b8c7f3dcdbecff856 Mon Sep 17 00:00:00 2001 From: Sylvain <35365065+sanderegg@users.noreply.github.com> Date: Mon, 22 May 2023 16:39:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20passing=20data=20from=20a=20serv?= =?UTF-8?q?ice=20to=20another=20fails=20(#4257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catalog/_handlers.py | 29 +++++++++++++------ .../unit/with_dbs/01/test_catalog_api.py | 3 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/catalog/_handlers.py b/services/web/server/src/simcore_service_webserver/catalog/_handlers.py index f5df935b39a..6659915625c 100644 --- a/services/web/server/src/simcore_service_webserver/catalog/_handlers.py +++ b/services/web/server/src/simcore_service_webserver/catalog/_handlers.py @@ -5,19 +5,20 @@ """ import logging +import urllib.parse from typing import Any, Iterator import orjson from aiohttp import web from aiohttp.web import Request, RouteTableDef -from models_library.services import ServiceInput, ServiceKeyEncoded, ServiceOutput +from models_library.services import ServiceInput, ServiceOutput from models_library.services_resources import ( ServiceResourcesDict, ServiceResourcesDictHelpers, ) from models_library.users import UserID from pint import UnitRegistry -from pydantic import BaseModel, Extra, Field +from pydantic import BaseModel, Extra, Field, validator from servicelib.aiohttp.requests_validation import ( handle_validation_as_http_error, parse_request_path_parameters_as, @@ -74,13 +75,21 @@ def create(cls, request: Request) -> "_RequestContext": class _ServicePathParams(BaseModel): - service_key: ServiceKeyEncoded + service_key: ServiceKey service_version: ServiceVersion class Config: allow_population_by_field_name = True extra = Extra.forbid + @validator("service_key", pre=True) + @classmethod + def ensure_unquoted(cls, v): + # NOTE: this is needed as in pytest mode, the aiohttp server does not seem to unquote automatically + if v is not None: + return urllib.parse.unquote(v) + return v + @routes.get(f"{VTAG}/catalog/services") @login_required @@ -120,7 +129,10 @@ async def update_service_handler(request: Request): # Evaluate and return validated model data = await update_service( - path_params.service_key, path_params.service_version, update_data, ctx + path_params.service_key, + path_params.service_version, + update_data, + ctx, ) return envelope_json_response(data) @@ -157,7 +169,10 @@ async def get_service_input_handler(request: Request): # Evaluate and return validated model response_model = await get_service_input( - path_params.service_key, path_params.service_version, path_params.input_key, ctx + path_params.service_key, + path_params.service_version, + path_params.input_key, + ctx, ) data = response_model.dict(**RESPONSE_MODEL_POLICY) @@ -278,7 +293,6 @@ async def get_service_resources_handler(request: Request): """ ctx = _RequestContext.create(request) path_params = parse_request_path_parameters_as(_ServicePathParams, request) - service_resources: ServiceResourcesDict = await client.get_service_resources( request.app, user_id=ctx.user_id, @@ -357,7 +371,6 @@ async def update_service( async def list_service_inputs( service_key: ServiceKey, service_version: ServiceVersion, ctx: _RequestContext ) -> list[ServiceOutputGet]: - service = await client.get_service( ctx.app, ctx.user_id, service_key, service_version, ctx.product_name ) @@ -376,7 +389,6 @@ async def get_service_input( input_key: ServiceInputKey, ctx: _RequestContext, ) -> ServiceInputGet: - service = await client.get_service( ctx.app, ctx.user_id, service_key, service_version, ctx.product_name ) @@ -471,7 +483,6 @@ async def get_compatible_outputs_given_target_input( to_input_key: ServiceInputKey, ctx: _RequestContext, ) -> list[ServiceOutputKey]: - # N outputs service_outputs = await list_service_outputs(service_key, service_version, ctx) diff --git a/services/web/server/tests/unit/with_dbs/01/test_catalog_api.py b/services/web/server/tests/unit/with_dbs/01/test_catalog_api.py index 5b814f5a56f..9515e25f378 100644 --- a/services/web/server/tests/unit/with_dbs/01/test_catalog_api.py +++ b/services/web/server/tests/unit/with_dbs/01/test_catalog_api.py @@ -3,6 +3,7 @@ # pylint:disable=redefined-outer-name import re +import urllib.parse import pytest from aiohttp import web @@ -118,7 +119,7 @@ async def test_get_service_resources( assert client.app assert client.app.router url = client.app.router["get_service_resources_handler"].url_for( - service_key="simcore%2Fservices%2Fdynamic%2Fsomeservice", + service_key=urllib.parse.quote("simcore/services/dynamic/someservice", safe=""), service_version="3.4.5", ) response = await client.get(f"{url}")