From cef92a98fc0177c5029f38f9d500e85893a422c8 Mon Sep 17 00:00:00 2001 From: Pedro Miguel Pereira Serrano Martins Date: Thu, 24 Feb 2022 18:24:47 +0100 Subject: [PATCH] fixing failure to fetch files with commas (#359) * fixing failure to fetch files with commas * changed filter in test * Update tests/darwin/dataset/remote_dataset_test.py Co-authored-by: Andrea Azzini Co-authored-by: Andrea Azzini --- darwin/dataset/remote_dataset.py | 4 ++-- tests/darwin/dataset/remote_dataset_test.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/darwin/dataset/remote_dataset.py b/darwin/dataset/remote_dataset.py index 18d0918f0..521d493b3 100644 --- a/darwin/dataset/remote_dataset.py +++ b/darwin/dataset/remote_dataset.py @@ -402,14 +402,14 @@ def fetch_remote_files( Iterator[DatasetItem] An iterator of ``DatasetItem``. """ - post_filters: Dict[str, str] = {} + post_filters: Dict[str, Union[str, List[str]]] = {} post_sort: Dict[str, str] = {} if filters: for list_type in ["filenames", "statuses"]: if list_type in filters: if type(filters[list_type]) is list: - post_filters[list_type] = ",".join(filters[list_type]) + post_filters[list_type] = filters[list_type] else: post_filters[list_type] = str(filters[list_type]) if "path" in filters: diff --git a/tests/darwin/dataset/remote_dataset_test.py b/tests/darwin/dataset/remote_dataset_test.py index 56142f6b1..fbd96cbad 100644 --- a/tests/darwin/dataset/remote_dataset_test.py +++ b/tests/darwin/dataset/remote_dataset_test.py @@ -378,6 +378,27 @@ def it_works(darwin_client: Client, dataset_name: str, dataset_slug: str, team_s assert item_1.id == 386074 assert item_2.id == 386073 + @responses.activate + def it_fetches_files_with_commas( + darwin_client: Client, dataset_name: str, dataset_slug: str, team_slug: str, files_content: dict + ): + remote_dataset = RemoteDataset( + client=darwin_client, team=team_slug, name=dataset_name, slug=dataset_slug, dataset_id=1 + ) + url = "http://localhost/api/datasets/1/items?page%5Bsize%5D=500" + responses.add( + responses.POST, + url, + json=files_content, + status=200, + ) + + list(remote_dataset.fetch_remote_files({"filenames": ["example,with, comma.mp4"]})) + + request_body = json.loads(responses.calls[0].request.body) + + assert request_body["filter"]["filenames"] == ["example,with, comma.mp4"] + @pytest.fixture def remote_dataset(darwin_client: Client, dataset_name: str, dataset_slug: str, team_slug: str):