From 545de4cc649d5ab9b4498c95f5557ed2ba17e4e6 Mon Sep 17 00:00:00 2001 From: Jawad Khan Date: Fri, 14 Nov 2025 16:16:40 +0500 Subject: [PATCH 1/5] feat: Added sharding support for python sdk --- meilisearch/models/task.py | 1 + .../test_client_multi_search_meilisearch.py | 3 ++ tests/client/test_client_network.py | 14 ++++++-- tests/client/test_client_sharding.py | 35 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/client/test_client_sharding.py diff --git a/meilisearch/models/task.py b/meilisearch/models/task.py index 2e856a6c..83735c73 100644 --- a/meilisearch/models/task.py +++ b/meilisearch/models/task.py @@ -21,6 +21,7 @@ class Task(CamelBase): enqueued_at: datetime started_at: Optional[datetime] = None finished_at: Optional[datetime] = None + network: Optional[Dict[str, Any]] = None if is_pydantic_2(): diff --git a/tests/client/test_client_multi_search_meilisearch.py b/tests/client/test_client_multi_search_meilisearch.py index 324a6747..29cf4206 100644 --- a/tests/client/test_client_multi_search_meilisearch.py +++ b/tests/client/test_client_multi_search_meilisearch.py @@ -84,14 +84,17 @@ def test_multi_search_with_network(client, index_with_documents): resp = client.add_or_update_networks( { "self": REMOTE_MS_1, + "sharding": True, "remotes": { REMOTE_MS_1: { "url": "http://ms-1235.example.meilisearch.io", "searchApiKey": "xxxxxxxx", + "writeApiKey": "xxxxxxxx", }, REMOTE_MS_2: { "url": "http://ms-1255.example.meilisearch.io", "searchApiKey": "xxxxxxxx", + "writeApiKey": "xxxxxxxx", }, }, } diff --git a/tests/client/test_client_network.py b/tests/client/test_client_network.py index bb6ba73a..1011b8b0 100644 --- a/tests/client/test_client_network.py +++ b/tests/client/test_client_network.py @@ -16,15 +16,25 @@ def test_add_or_update_networks(client): """Tests upsert network remote instance.""" body = { "self": REMOTE_MS_1, + "sharding": True, "remotes": { - REMOTE_MS_1: {"url": "http://localhost:7700", "searchApiKey": "xxxxxxxxxxxxxx"}, - REMOTE_MS_2: {"url": "http://localhost:7720", "searchApiKey": "xxxxxxxxxxxxxxx"}, + REMOTE_MS_1: { + "url": "http://localhost:7700", + "searchApiKey": "xxxxxxxxxxxxxx", + "writeApiKey": "xxxxxxxxx", + }, + REMOTE_MS_2: { + "url": "http://localhost:7720", + "searchApiKey": "xxxxxxxxxxxxxxx", + "writeApiKey": "xxxxxxxx", + }, }, } response = client.add_or_update_networks(body=body) assert isinstance(response, dict) assert response["self"] == REMOTE_MS_1 + assert response["sharding"] is True assert len(response["remotes"]) >= 2 assert REMOTE_MS_2 in response["remotes"] assert REMOTE_MS_1 in response["remotes"] diff --git a/tests/client/test_client_sharding.py b/tests/client/test_client_sharding.py new file mode 100644 index 00000000..07c4fcf6 --- /dev/null +++ b/tests/client/test_client_sharding.py @@ -0,0 +1,35 @@ +import pytest + +from tests.common import BASE_URL, REMOTE_MS_1 + + +@pytest.mark.usefixtures("enable_network_options") +def test_update_and_get_network_settings(client): + """Test updating and getting network settings.""" + instance_name = REMOTE_MS_1 + options = { + "self": instance_name, + "remotes": { + instance_name: { + "url": BASE_URL, + "searchApiKey": "search-key-1", + "writeApiKey": "write-key-1", + } + }, + "sharding": True, + } + + client.add_or_update_networks(options) + response = client.get_all_networks() + + assert response["self"] == options["self"] + assert response["remotes"][instance_name]["url"] == options["remotes"][instance_name]["url"] + assert ( + response["remotes"][instance_name]["searchApiKey"] + == options["remotes"][instance_name]["searchApiKey"] + ) + assert ( + response["remotes"][instance_name]["writeApiKey"] + == options["remotes"][instance_name]["writeApiKey"] + ) + assert response["sharding"] == options["sharding"] From bea059e898c224ffe7cf5b3ea1ddb56b7298e726 Mon Sep 17 00:00:00 2001 From: Jawad Khan Date: Fri, 21 Nov 2025 16:35:37 +0500 Subject: [PATCH 2/5] fix: fixed test cases --- tests/client/test_client_multi_search_meilisearch.py | 2 ++ tests/client/test_client_network.py | 3 +++ tests/client/test_client_sharding.py | 2 ++ tests/test_utils.py | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/tests/client/test_client_multi_search_meilisearch.py b/tests/client/test_client_multi_search_meilisearch.py index 29cf4206..b9523e0b 100644 --- a/tests/client/test_client_multi_search_meilisearch.py +++ b/tests/client/test_client_multi_search_meilisearch.py @@ -2,6 +2,7 @@ from meilisearch.errors import MeilisearchApiError from tests.common import INDEX_UID, REMOTE_MS_1, REMOTE_MS_2 +from tests.test_utils import disable_sharding def test_basic_multi_search(client, empty_index): @@ -111,3 +112,4 @@ def test_multi_search_with_network(client, index_with_documents): assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID assert response["hits"][0]["_federation"]["remote"] == REMOTE_MS_1 assert response["remoteErrors"] == {} + disable_sharding(client) diff --git a/tests/client/test_client_network.py b/tests/client/test_client_network.py index 1011b8b0..7037b62e 100644 --- a/tests/client/test_client_network.py +++ b/tests/client/test_client_network.py @@ -1,6 +1,7 @@ import pytest from tests.common import REMOTE_MS_1, REMOTE_MS_2 +from tests.test_utils import disable_sharding @pytest.mark.usefixtures("enable_network_options") @@ -38,3 +39,5 @@ def test_add_or_update_networks(client): assert len(response["remotes"]) >= 2 assert REMOTE_MS_2 in response["remotes"] assert REMOTE_MS_1 in response["remotes"] + + disable_sharding(client) diff --git a/tests/client/test_client_sharding.py b/tests/client/test_client_sharding.py index 07c4fcf6..aadab4e2 100644 --- a/tests/client/test_client_sharding.py +++ b/tests/client/test_client_sharding.py @@ -1,6 +1,7 @@ import pytest from tests.common import BASE_URL, REMOTE_MS_1 +from tests.test_utils import disable_sharding @pytest.mark.usefixtures("enable_network_options") @@ -33,3 +34,4 @@ def test_update_and_get_network_settings(client): == options["remotes"][instance_name]["writeApiKey"] ) assert response["sharding"] == options["sharding"] + disable_sharding(client) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4c8c4651..407b2612 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -31,3 +31,7 @@ def test_iso_to_date_time(iso_date, expected): def test_iso_to_date_time_invalid_format(): with pytest.raises(ValueError): iso_to_date_time("2023-07-13T23:37:20Z") + + +def disable_sharding(client): + client.add_or_update_networks(body={"sharding": False}) From 8590aac74db4279ead49c151119c6a0953cb6ccd Mon Sep 17 00:00:00 2001 From: Laurent Cazanove Date: Mon, 24 Nov 2025 16:48:47 +0800 Subject: [PATCH 3/5] Apply suggestion from @Strift --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 407b2612..1d87ed72 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,6 +32,6 @@ def test_iso_to_date_time_invalid_format(): with pytest.raises(ValueError): iso_to_date_time("2023-07-13T23:37:20Z") - +# TODO: refactor to use the unified API to toggle experimental features def disable_sharding(client): client.add_or_update_networks(body={"sharding": False}) From 44c02c390369b0e6c6bf9dead31339cb10dce9ee Mon Sep 17 00:00:00 2001 From: Laurent Cazanove Date: Mon, 24 Nov 2025 17:08:33 +0800 Subject: [PATCH 4/5] Apply suggestion from @Strift --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1d87ed72..d43ab5e8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,6 +32,6 @@ def test_iso_to_date_time_invalid_format(): with pytest.raises(ValueError): iso_to_date_time("2023-07-13T23:37:20Z") -# TODO: refactor to use the unified API to toggle experimental features +# Refactor to use the unified API to toggle experimental features def disable_sharding(client): client.add_or_update_networks(body={"sharding": False}) From a2e8c973844def427897d88ec8e2e954265888fe Mon Sep 17 00:00:00 2001 From: Laurent Cazanove Date: Mon, 24 Nov 2025 17:17:22 +0800 Subject: [PATCH 5/5] Formatting --- tests/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index d43ab5e8..7b9feace 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,6 +32,7 @@ def test_iso_to_date_time_invalid_format(): with pytest.raises(ValueError): iso_to_date_time("2023-07-13T23:37:20Z") + # Refactor to use the unified API to toggle experimental features def disable_sharding(client): client.add_or_update_networks(body={"sharding": False})