Skip to content
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
1 change: 1 addition & 0 deletions meilisearch/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down
5 changes: 5 additions & 0 deletions tests/client/test_client_multi_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -84,14 +85,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",
},
},
}
Expand All @@ -108,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)
17 changes: 15 additions & 2 deletions tests/client/test_client_network.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -16,15 +17,27 @@ 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"]

disable_sharding(client)
37 changes: 37 additions & 0 deletions tests/client/test_client_sharding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from tests.common import BASE_URL, REMOTE_MS_1
from tests.test_utils import disable_sharding


@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"]
disable_sharding(client)
5 changes: 5 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ 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")


# Refactor to use the unified API to toggle experimental features
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify or remove the comment.

The comment suggests a future refactor ("Refactor to use the unified API..."), but the code already uses add_or_update_networks, which appears to be the unified API. Either remove the comment if the refactor is complete, or reword it to accurately describe the function's current purpose.

Consider replacing with a descriptive comment:

-# Refactor to use the unified API to toggle experimental features
+# Helper to disable sharding via the network API
 def disable_sharding(client):
     client.add_or_update_networks(body={"sharding": False})

Or remove the comment entirely if the function name is self-explanatory.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Refactor to use the unified API to toggle experimental features
# Helper to disable sharding via the network API
def disable_sharding(client):
client.add_or_update_networks(body={"sharding": False})
🤖 Prompt for AI Agents
In tests/test_utils.py around line 36, the inline comment "Refactor to use the
unified API to toggle experimental features" is outdated or misleading because
the code already calls add_or_update_networks; update the comment to accurately
describe what the test helper does (e.g., "Use add_or_update_networks to
configure test networks") or remove the comment entirely if the function name is
self-explanatory, ensuring the remaining comment (if any) is concise and
describes current behavior.

def disable_sharding(client):
client.add_or_update_networks(body={"sharding": False})
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add type hints for clarity.

The function signature lacks type hints for the client parameter and return type, which would improve code clarity and enable better IDE support.

Apply this diff to add type hints:

-def disable_sharding(client):
+def disable_sharding(client: "meilisearch.Client") -> None:
     client.add_or_update_networks(body={"sharding": False})

Optionally, add a docstring to document the helper's purpose:

def disable_sharding(client: "meilisearch.Client") -> None:
    """Disable sharding experimental feature via the network API."""
    client.add_or_update_networks(body={"sharding": False})
🤖 Prompt for AI Agents
In tests/test_utils.py around lines 36 to 37, add type hints to the
disable_sharding function signature and return type (e.g., client:
"meilisearch.Client" -> None) to improve clarity and IDE support; update the
function definition accordingly and optionally add a one-line docstring
describing its purpose ("Disable sharding experimental feature via the network
API.") — use a string forward reference if meilisearch.Client is not imported at
top.