Skip to content

Commit

Permalink
fix: query filter in list task endpoint (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush5120 authored Jul 22, 2024
1 parent 4198f71 commit 0920812
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions pro_tes/ga4gh/tes/task_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"}

Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions pro_tes/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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: "
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0920812

Please sign in to comment.