From 0920812798c17d443889bb3d6e2a3523e621c52b Mon Sep 17 00:00:00 2001 From: Ayush Kumar <64720666+Ayush5120@users.noreply.github.com> Date: Mon, 22 Jul 2024 19:33:36 +0530 Subject: [PATCH] fix: query filter in list task endpoint (#178) --- docker-compose.yaml | 2 +- pro_tes/ga4gh/tes/task_runs.py | 10 ++++++---- pro_tes/utils/db.py | 10 ++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 5565bc2..ed13acc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -36,7 +36,7 @@ services: - "5672:5672" mongodb: - image: mongo:3.2 + image: mongo:3.6 restart: unless-stopped volumes: - ${PROTES_DATA_DIR:-../data/pro_tes}/db:/data/db diff --git a/pro_tes/ga4gh/tes/task_runs.py b/pro_tes/ga4gh/tes/task_runs.py index 308aec1..55fa504 100644 --- a/pro_tes/ga4gh/tes/task_runs.py +++ b/pro_tes/ga4gh/tes/task_runs.py @@ -272,15 +272,17 @@ def list_tasks(self, **kwargs) -> dict: ) page_token = kwargs.get("page_token") filter_dict = {} - filter_dict["user_id"] = kwargs.get("user_id") + + user_id = kwargs.get("user_id") + if user_id is not None: + filter_dict["user_id"] = user_id if page_token is not None: filter_dict["_id"] = {"$lt": ObjectId(page_token)} view = kwargs.get("view", "BASIC") projection = self._set_projection(view=view) - name_prefix: str = str(kwargs.get("name_prefix")) - + name_prefix = kwargs.get("name_prefix") if name_prefix is not None: filter_dict["task_original.name"] = {"$regex": f"^{name_prefix}"} @@ -437,7 +439,7 @@ def _write_doc_to_db( ) document.worker_id = uuid() try: - self.db_client.insert(document.dict(exclude_none=True)) + self.db_client.insert_one(document.dict(exclude_none=True)) except DuplicateKeyError: continue assert document is not None diff --git a/pro_tes/utils/db.py b/pro_tes/utils/db.py index 9e8cd40..511e9cf 100644 --- a/pro_tes/utils/db.py +++ b/pro_tes/utils/db.py @@ -2,9 +2,7 @@ import logging from typing import Mapping, Optional -from pymongo.collection import ReturnDocument # type: ignore -from pymongo import collection as Collection # type: ignore - +from pymongo.collection import ReturnDocument, Collection from pro_tes.ga4gh.tes.models import DbDocument, TesState logger = logging.getLogger(__name__) @@ -56,7 +54,7 @@ def get_document( projection=projection, ) try: - document: DbDocument = DbDocument(**document_unvalidated) + document: DbDocument = DbDocument(**(document_unvalidated or {})) except Exception as exc: raise ValueError( "Database document does not conform to schema: " @@ -110,8 +108,8 @@ def upsert_fields_in_root_object( {"worker_id": self.worker_id}, { "$set": { - ".".join([root, key]): value - for (key, value) in kwargs.items() + ".".join([root, key]): value for (key, value) in + kwargs.items() } }, projection=projection,