feat: Added customMetadata in index apis
Related issue
Fixes #1168
What does this PR do?
Update Index APIs to Support customMetadata
This PR updates the index-related APIs in the Python SDK to align with recent Meilisearch server changes and adds support for the new customMetadata field.
Key Updates
-
Added customMetadata support across index creation and update methods.
-
Synced request/response structures with the latest Meilisearch index API.
-
...
PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
-
New Features
- Tasks now support custom metadata. Document operations (add, update, delete, single and batched) accept an optional metadata parameter that is attached to the created task and returned in task info for improved tracking.
-
Tests
- Tests updated to verify metadata is propagated and exposed on returned task information after operations.
✏️ Tip: You can customize this high-level summary in your review settings.
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
📝 Walkthrough
Walkthrough
Adds an optional metadata parameter to client, index, and task APIs; threads it into URL query strings and request parameters as customMetadata; and surfaces server-returned metadata on Task objects via a new custom_metadata field. Tests updated to assert metadata propagation for document operations.
Changes
| Cohort / File(s) | Summary |
|---|---|
Index API methods meilisearch/index.py |
Many public index methods now accept metadata: Optional[str] = None (create, update, delete, add/update/delete documents, batch/raw/CSV/NDJSON variants). _build_url accepts metadata and appends customMetadata to query strings when present; metadata is propagated into HTTP calls and to task parsing. |
Client methods meilisearch/client.py |
create_index, delete_index, cancel_tasks, and delete_tasks signatures extended to accept metadata and forward it into index/task operations. |
Task handlers meilisearch/task.py |
cancel_tasks and delete_tasks accept metadata and insert customMetadata into request parameters when provided. |
Task model meilisearch/models/task.py |
Added custom_metadata: Optional[str] = None field on Task model to capture server-returned metadata (snake_case). |
Tests tests/index/test_index_document_meilisearch.py |
Tests updated to pass metadata="Test metadata" to add/update/delete document variants (single, batched, JSON/CSV/NDJSON/raw) and assert returned TaskInfo .custom_metadata equals the supplied value. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Client
participant Index
participant HTTP
participant Server
participant TaskModel
Client->>Index: add_documents(..., metadata="Test metadata")
Note right of Index: metadata threaded through\nmethod stack and _build_url
Index->>HTTP: POST /indexes/{uid}/documents?customMetadata=Test%20metadata + body
HTTP->>Server: send request
Server-->>HTTP: 202 Accepted (task JSON including customMetadata)
HTTP->>Index: response
Index->>TaskModel: parse task JSON -> Task.custom_metadata
TaskModel-->>Client: TaskInfo with custom_metadata="Test metadata"
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
🐇 I hopped through code with whiskers twitching bright,
Tucked tiny notes in tasks, a soft delight.
Now every job can carry a little song,
A ribbon of metadata, humming along.
Hooray — I left a carrot-shaped byte tonight!
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Linked Issues check | ✅ Passed | The PR successfully implements the requirements from issue #1168 by adding optional metadata parameter across all specified endpoints (POST/PUT/DELETE documents) with test coverage validating metadata propagation. |
| Out of Scope Changes check | ✅ Passed | All changes are focused on adding metadata support to document-related and index management methods as specified in issue #1168; no unrelated changes detected. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%. |
| Title check | ✅ Passed | The title 'feat: add custom_metadata in index APIs' clearly and concisely summarizes the main change—adding custom_metadata support to index APIs across the SDK. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- [ ] 📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@Strift Tests are failing because sharding require Enterprose addition now. Should we adjust test cases or somehow we can skip this check.
@Strift Please re trigger test cases.
@Strift This is ready from my side.
@Strift It's ready now.