Skip to content

Commit 0920812

Browse files
authoredJul 22, 2024··
fix: query filter in list task endpoint (#178)
1 parent 4198f71 commit 0920812

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed
 

‎docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
- "5672:5672"
3737

3838
mongodb:
39-
image: mongo:3.2
39+
image: mongo:3.6
4040
restart: unless-stopped
4141
volumes:
4242
- ${PROTES_DATA_DIR:-../data/pro_tes}/db:/data/db

‎pro_tes/ga4gh/tes/task_runs.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,17 @@ def list_tasks(self, **kwargs) -> dict:
272272
)
273273
page_token = kwargs.get("page_token")
274274
filter_dict = {}
275-
filter_dict["user_id"] = kwargs.get("user_id")
275+
276+
user_id = kwargs.get("user_id")
277+
if user_id is not None:
278+
filter_dict["user_id"] = user_id
276279

277280
if page_token is not None:
278281
filter_dict["_id"] = {"$lt": ObjectId(page_token)}
279282
view = kwargs.get("view", "BASIC")
280283
projection = self._set_projection(view=view)
281284

282-
name_prefix: str = str(kwargs.get("name_prefix"))
283-
285+
name_prefix = kwargs.get("name_prefix")
284286
if name_prefix is not None:
285287
filter_dict["task_original.name"] = {"$regex": f"^{name_prefix}"}
286288

@@ -437,7 +439,7 @@ def _write_doc_to_db(
437439
)
438440
document.worker_id = uuid()
439441
try:
440-
self.db_client.insert(document.dict(exclude_none=True))
442+
self.db_client.insert_one(document.dict(exclude_none=True))
441443
except DuplicateKeyError:
442444
continue
443445
assert document is not None

‎pro_tes/utils/db.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import logging
44
from typing import Mapping, Optional
5-
from pymongo.collection import ReturnDocument # type: ignore
6-
from pymongo import collection as Collection # type: ignore
7-
5+
from pymongo.collection import ReturnDocument, Collection
86
from pro_tes.ga4gh.tes.models import DbDocument, TesState
97

108
logger = logging.getLogger(__name__)
@@ -56,7 +54,7 @@ def get_document(
5654
projection=projection,
5755
)
5856
try:
59-
document: DbDocument = DbDocument(**document_unvalidated)
57+
document: DbDocument = DbDocument(**(document_unvalidated or {}))
6058
except Exception as exc:
6159
raise ValueError(
6260
"Database document does not conform to schema: "
@@ -110,8 +108,8 @@ def upsert_fields_in_root_object(
110108
{"worker_id": self.worker_id},
111109
{
112110
"$set": {
113-
".".join([root, key]): value
114-
for (key, value) in kwargs.items()
111+
".".join([root, key]): value for (key, value) in
112+
kwargs.items()
115113
}
116114
},
117115
projection=projection,

0 commit comments

Comments
 (0)
Please sign in to comment.