diff --git a/dcicutils/portal_utils.py b/dcicutils/portal_utils.py index ce541ddb5..b2378c75a 100644 --- a/dcicutils/portal_utils.py +++ b/dcicutils/portal_utils.py @@ -13,6 +13,7 @@ from requests.models import Response from threading import Thread from typing import Callable, Dict, List, Optional, Tuple, Type, Union +# from urllib.parse import parse_qs as parse_url_query_string from uuid import uuid4 as uuid from webtest.app import TestApp, TestResponse from wsgiref.simple_server import make_server as wsgi_make_server @@ -279,6 +280,8 @@ def get_metadata(self, object_id: str, raw: bool = False, database: bool = False limit: Optional[int] = None, offset: Optional[int] = None, field: Optional[str] = None, deleted: bool = False, raise_exception: bool = True) -> Optional[dict]: + if not isinstance(object_id, str): + return None if isinstance(raw, bool) and raw: add_on = "frame=raw" + ("&datastore=database" if isinstance(database, bool) and database else "") elif database: @@ -305,6 +308,13 @@ def get_metadata(self, object_id: str, raw: bool = False, database: bool = False add_on += "&status=deleted" else: add_on += "status=deleted" + if (question_mark := object_id.find("?")) > 0: + query_string = object_id[question_mark + 1:] + object_id = object_id[:question_mark] + if add_on: + add_on += f"&{query_string}" + else: + add_on += query_string if raise_exception: return get_metadata(obj_id=object_id, vapp=self.vapp, key=self.key, add_on=add_on) else: