From 1eacc43922104be514d626ac4831114f4378d2e1 Mon Sep 17 00:00:00 2001 From: Donny Winston Date: Mon, 13 Nov 2023 13:36:17 -0500 Subject: [PATCH] fix: coerce pydantic AnyUri to str when needed (#377) fixes #376 --- nmdc_runtime/site/resources.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nmdc_runtime/site/resources.py b/nmdc_runtime/site/resources.py index 5f857a77..22b22d6d 100644 --- a/nmdc_runtime/site/resources.py +++ b/nmdc_runtime/site/resources.py @@ -17,7 +17,7 @@ from fastjsonschema import JsonSchemaValueException from frozendict import frozendict from linkml_runtime.dumpers import json_dumper -from pydantic import BaseModel +from pydantic import BaseModel, AnyUrl from pymongo import MongoClient, ReplaceOne, InsertOne from terminusdb_client import WOQLClient from toolz import get_in @@ -194,15 +194,17 @@ def get_object_bytes(self, object_id) -> requests.Response: access = AccessURL( **self.get_object_access(object_id, method.access_id).json() ) - if access.url.startswith( + if str(access.url).startswith( os.getenv("API_HOST_EXTERNAL") ) and self.base_url == os.getenv("API_HOST"): - access.url = access.url.replace( - os.getenv("API_HOST_EXTERNAL"), os.getenv("API_HOST") + access.url = AnyUrl( + str(access.url).replace( + os.getenv("API_HOST_EXTERNAL"), os.getenv("API_HOST") + ) ) else: access = AccessURL(url=method.access_url.url) - return requests.get(access.url) + return requests.get(str(access.url)) def list_jobs(self, list_request=None): if list_request is None: