Skip to content

Commit

Permalink
🐛 passing data from a service to another fails (#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored May 22, 2023
1 parent 3ff6e30 commit f95c13f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# pylint:disable=redefined-outer-name

import re
import urllib.parse

import pytest
from aiohttp import web
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit f95c13f

Please sign in to comment.