-
Notifications
You must be signed in to change notification settings - Fork 110
feat: add get_task_documents to retrieve a task's documents #1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tcferreira
wants to merge
1
commit into
meilisearch:main
Choose a base branch
from
tcferreira:feat/get-task-documents
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import json | ||
| import re | ||
| from datetime import datetime | ||
| from functools import lru_cache | ||
| from typing import Union | ||
| from typing import Any, Dict, List, Union | ||
|
|
||
| import pydantic | ||
|
|
||
| _CONCATENATED_JSON = re.compile(r"(?<=\})\s*(?=\{)") | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def is_pydantic_2() -> bool: | ||
|
|
@@ -41,3 +45,28 @@ def iso_to_date_time(iso_date: Union[datetime, str, None]) -> Union[datetime, No | |
| reduce = len(split[1]) - 6 | ||
| reduced = f"{split[0]}.{split[1][:-reduce]}Z" | ||
| return datetime.strptime(reduced, "%Y-%m-%dT%H:%M:%S.%fZ") | ||
|
|
||
|
|
||
| def parse_task_documents(raw_documents: str) -> List[Dict[str, Any]]: | ||
| """Parse the payload returned by ``GET /tasks/{uid}/documents``. | ||
|
|
||
| The endpoint may return a JSON array, a single JSON object, NDJSON, or | ||
| several JSON objects concatenated without a separator. This normalizes all | ||
| of those formats into a list of documents. | ||
| """ | ||
| payload = raw_documents.strip() | ||
| if not payload: | ||
| return [] | ||
|
|
||
| try: | ||
| parsed = json.loads(payload) | ||
| except json.JSONDecodeError: | ||
| documents: List[Dict[str, Any]] = [] | ||
| for line in payload.splitlines(): | ||
| for chunk in _CONCATENATED_JSON.split(line): | ||
| stripped = chunk.strip() | ||
|
Comment on lines
+65
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use a JSON-aware concatenation parser instead of regex boundary splitting. Lines 65-67 can mis-split valid payloads when a document string contains Suggested fix except json.JSONDecodeError:
- documents: List[Dict[str, Any]] = []
- for line in payload.splitlines():
- for chunk in _CONCATENATED_JSON.split(line):
- stripped = chunk.strip()
- if stripped:
- documents.append(json.loads(stripped))
+ decoder = json.JSONDecoder()
+ documents: List[Dict[str, Any]] = []
+ idx = 0
+ while idx < len(payload):
+ while idx < len(payload) and payload[idx].isspace():
+ idx += 1
+ if idx >= len(payload):
+ break
+ document, idx = decoder.raw_decode(payload, idx)
+ documents.append(document)
return documents🤖 Prompt for AI Agents |
||
| if stripped: | ||
| documents.append(json.loads(stripped)) | ||
| return documents | ||
|
|
||
| return parsed if isinstance(parsed, list) else [parsed] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 168
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 237
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 237
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 199
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 236
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 1413
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 1078
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 203
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 425
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 11223
Add
InvalidSchemaexception handler toget_streamfor consistency.The
get_streammethod at lines 242-247 lacks anInvalidSchemahandler that exists in bothsend_requestandpost_stream. Malformed base URLs currently raise rawrequests.exceptions.InvalidSchemainstead of wrapping it inMeilisearchCommunicationError, breaking SDK-level exception behavior consistency.Suggested fix
except requests.exceptions.Timeout as err: raise MeilisearchTimeoutError(str(err)) from err except requests.exceptions.ConnectionError as err: raise MeilisearchCommunicationError(str(err)) from err except requests.exceptions.HTTPError as err: raise MeilisearchApiError(str(err), response) from err + except requests.exceptions.InvalidSchema as err: + if "://" not in self.config.url: + raise MeilisearchCommunicationError( + f""" + Invalid URL {self.config.url}, no scheme/protocol supplied. + Did you mean https://{self.config.url}? + """ + ) from err + + raise MeilisearchCommunicationError(str(err)) from err🤖 Prompt for AI Agents