Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaeb5313

Browse files
committed
Return helpful error when an empty list of docs are imported.
1 parentbb2a15c commitaeb5313

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎examples/collection_operations.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
importos
33
importsys
44
importtypesense
5-
5+
fromtypesense.exceptionsimportTypesenseClientError
66

77
curr_dir=os.path.dirname(os.path.realpath(__file__))
88
sys.path.insert(1,os.path.abspath(os.path.join(curr_dir,os.pardir)))
@@ -131,6 +131,13 @@
131131
# Deleting documents matching a filter query
132132
print(client.collections['books'].documents.delete({'filter_by':'ratings_count: 4780653'}))
133133

134+
# Try importing empy list
135+
try:
136+
import_results=client.collections['books'].documents.import_([], {"action":"upsert"})
137+
print(import_results)
138+
exceptTypesenseClientErrorase:
139+
print("Detected import of empty document list.")
140+
134141
# Drop the collection
135142
drop_response=client.collections['books'].delete()
136143
print(drop_response)

‎typesense/documents.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def import_(self, documents, params=None, batch_size=None):
7474
fordocumentindocuments:
7575
document_strs.append(json.dumps(document))
7676

77+
iflen(document_strs)==0:
78+
raiseTypesenseClientError(f"Cannot import an empty list of documents.")
79+
7780
docs_import='\n'.join(document_strs)
7881
api_response=self.api_call.post(self._endpoint_path('import'),docs_import,params,as_json=False)
7982
res_obj_strs=api_response.split('\n')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp