Skip to content

feat(templates): add request_options to python helpers consistently #3868

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

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
11 changes: 7 additions & 4 deletions templates/python/search_helpers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
{{^isSyncClient}}async {{/isSyncClient}}def generate_secured_api_key(
self,
parent_api_key: str,
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
restrictions: Optional[Union[dict, SecuredApiKeyRestrictions]] = SecuredApiKeyRestrictions(),
) -> str:
"""
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
Expand Down Expand Up @@ -244,32 +244,35 @@
self,
index_name: str,
objects: List[Dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
"""
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.ADDOBJECT)
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.ADDOBJECT, request_options=request_options)

{{^isSyncClient}}async {{/isSyncClient}}def delete_objects(
self,
index_name: str,
object_ids: List[str],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
"""
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=[{"objectID": id} for id in object_ids], action=Action.DELETEOBJECT)
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=[{"objectID": id} for id in object_ids], action=Action.DELETEOBJECT, request_options=request_options)

{{^isSyncClient}}async {{/isSyncClient}}def partial_update_objects(
self,
index_name: str,
objects: List[Dict[str, Any]],
create_if_not_exists: Optional[bool] = False,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
"""
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.PARTIALUPDATEOBJECT if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE)
return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.PARTIALUPDATEOBJECT if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE, request_options=request_options)

{{^isSyncClient}}async {{/isSyncClient}}def chunked_batch(
self,
Expand Down
Loading