Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query filter in list task endpoint #178

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
uniqueg marked this conversation as resolved.
Show resolved Hide resolved
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")
uniqueg marked this conversation as resolved.
Show resolved Hide resolved
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
Loading