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

🐛 passing data from a service to another fails #4257

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
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
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
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