Skip to content

Commit d43103a

Browse files
committed
feat: Added sharding support for python sdk
1 parent a54e3c2 commit d43103a

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

meilisearch/models/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Task(CamelBase):
2121
enqueued_at: datetime
2222
started_at: Optional[datetime] = None
2323
finished_at: Optional[datetime] = None
24+
network: Optional[Dict[str, Any]] = None
2425

2526
if is_pydantic_2():
2627

tests/client/test_client_multi_search_meilisearch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ def test_multi_search_with_network(client, index_with_documents):
8484
resp = client.add_or_update_networks(
8585
{
8686
"self": REMOTE_MS_1,
87+
"sharding": True,
8788
"remotes": {
8889
REMOTE_MS_1: {
8990
"url": "http://ms-1235.example.meilisearch.io",
9091
"searchApiKey": "xxxxxxxx",
92+
"writeApiKey": "xxxxxxxx",
9193
},
9294
REMOTE_MS_2: {
9395
"url": "http://ms-1255.example.meilisearch.io",
9496
"searchApiKey": "xxxxxxxx",
97+
"writeApiKey": "xxxxxxxx",
9598
},
9699
},
97100
}

tests/client/test_client_network.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,25 @@ def test_add_or_update_networks(client):
1616
"""Tests upsert network remote instance."""
1717
body = {
1818
"self": REMOTE_MS_1,
19+
"sharding": True,
1920
"remotes": {
20-
REMOTE_MS_1: {"url": "http://localhost:7700", "searchApiKey": "xxxxxxxxxxxxxx"},
21-
REMOTE_MS_2: {"url": "http://localhost:7720", "searchApiKey": "xxxxxxxxxxxxxxx"},
21+
REMOTE_MS_1: {
22+
"url": "http://localhost:7700",
23+
"searchApiKey": "xxxxxxxxxxxxxx",
24+
"writeApiKey": "xxxxxxxxx",
25+
},
26+
REMOTE_MS_2: {
27+
"url": "http://localhost:7720",
28+
"searchApiKey": "xxxxxxxxxxxxxxx",
29+
"writeApiKey": "xxxxxxxx",
30+
},
2231
},
2332
}
2433
response = client.add_or_update_networks(body=body)
2534

2635
assert isinstance(response, dict)
2736
assert response["self"] == REMOTE_MS_1
37+
assert response["sharding"] is True
2838
assert len(response["remotes"]) >= 2
2939
assert REMOTE_MS_2 in response["remotes"]
3040
assert REMOTE_MS_1 in response["remotes"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
3+
from tests.common import BASE_URL, REMOTE_MS_1
4+
5+
6+
@pytest.mark.usefixtures("enable_network_options")
7+
def test_update_and_get_network_settings(client):
8+
"""Test updating and getting network settings."""
9+
instance_name = REMOTE_MS_1
10+
options = {
11+
"self": instance_name,
12+
"remotes": {
13+
instance_name: {
14+
"url": BASE_URL,
15+
"searchApiKey": "search-key-1",
16+
"writeApiKey": "write-key-1",
17+
}
18+
},
19+
"sharding": True,
20+
}
21+
22+
client.add_or_update_networks(options)
23+
response = client.get_all_networks()
24+
25+
assert response["self"] == options["self"]
26+
assert response["remotes"][instance_name]["url"] == options["remotes"][instance_name]["url"]
27+
assert (
28+
response["remotes"][instance_name]["searchApiKey"]
29+
== options["remotes"][instance_name]["searchApiKey"]
30+
)
31+
assert (
32+
response["remotes"][instance_name]["writeApiKey"]
33+
== options["remotes"][instance_name]["writeApiKey"]
34+
)
35+
assert response["sharding"] == options["sharding"]

0 commit comments

Comments
 (0)