Skip to content

Commit a7aac98

Browse files
algolia-botkai687
andcommitted
fix: accept dict for generate_secured_api_key (generated)
Co-authored-by: Kai Welke <[email protected]>
1 parent e3d7b7c commit a7aac98

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ async def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
420420
async def generate_secured_api_key(
421421
self,
422422
parent_api_key: str,
423-
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
423+
restrictions: Optional[
424+
Union[dict, SecuredApiKeyRestrictions]
425+
] = SecuredApiKeyRestrictions(),
424426
) -> str:
425427
"""
426428
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
@@ -470,18 +472,23 @@ async def save_objects(
470472
self,
471473
index_name: str,
472474
objects: List[Dict[str, Any]],
475+
request_options: Optional[Union[dict, RequestOptions]] = None,
473476
) -> List[BatchResponse]:
474477
"""
475478
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.
476479
"""
477480
return await self.chunked_batch(
478-
index_name=index_name, objects=objects, action=Action.ADDOBJECT
481+
index_name=index_name,
482+
objects=objects,
483+
action=Action.ADDOBJECT,
484+
request_options=request_options,
479485
)
480486

481487
async def delete_objects(
482488
self,
483489
index_name: str,
484490
object_ids: List[str],
491+
request_options: Optional[Union[dict, RequestOptions]] = None,
485492
) -> List[BatchResponse]:
486493
"""
487494
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.
@@ -490,13 +497,15 @@ async def delete_objects(
490497
index_name=index_name,
491498
objects=[{"objectID": id} for id in object_ids],
492499
action=Action.DELETEOBJECT,
500+
request_options=request_options,
493501
)
494502

495503
async def partial_update_objects(
496504
self,
497505
index_name: str,
498506
objects: List[Dict[str, Any]],
499507
create_if_not_exists: Optional[bool] = False,
508+
request_options: Optional[Union[dict, RequestOptions]] = None,
500509
) -> List[BatchResponse]:
501510
"""
502511
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.
@@ -507,6 +516,7 @@ async def partial_update_objects(
507516
action=Action.PARTIALUPDATEOBJECT
508517
if create_if_not_exists
509518
else Action.PARTIALUPDATEOBJECTNOCREATE,
519+
request_options=request_options,
510520
)
511521

512522
async def chunked_batch(
@@ -5346,7 +5356,9 @@ def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
53465356
def generate_secured_api_key(
53475357
self,
53485358
parent_api_key: str,
5349-
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
5359+
restrictions: Optional[
5360+
Union[dict, SecuredApiKeyRestrictions]
5361+
] = SecuredApiKeyRestrictions(),
53505362
) -> str:
53515363
"""
53525364
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
@@ -5396,18 +5408,23 @@ def save_objects(
53965408
self,
53975409
index_name: str,
53985410
objects: List[Dict[str, Any]],
5411+
request_options: Optional[Union[dict, RequestOptions]] = None,
53995412
) -> List[BatchResponse]:
54005413
"""
54015414
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.
54025415
"""
54035416
return self.chunked_batch(
5404-
index_name=index_name, objects=objects, action=Action.ADDOBJECT
5417+
index_name=index_name,
5418+
objects=objects,
5419+
action=Action.ADDOBJECT,
5420+
request_options=request_options,
54055421
)
54065422

54075423
def delete_objects(
54085424
self,
54095425
index_name: str,
54105426
object_ids: List[str],
5427+
request_options: Optional[Union[dict, RequestOptions]] = None,
54115428
) -> List[BatchResponse]:
54125429
"""
54135430
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.
@@ -5416,13 +5433,15 @@ def delete_objects(
54165433
index_name=index_name,
54175434
objects=[{"objectID": id} for id in object_ids],
54185435
action=Action.DELETEOBJECT,
5436+
request_options=request_options,
54195437
)
54205438

54215439
def partial_update_objects(
54225440
self,
54235441
index_name: str,
54245442
objects: List[Dict[str, Any]],
54255443
create_if_not_exists: Optional[bool] = False,
5444+
request_options: Optional[Union[dict, RequestOptions]] = None,
54265445
) -> List[BatchResponse]:
54275446
"""
54285447
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.
@@ -5433,6 +5452,7 @@ def partial_update_objects(
54335452
action=Action.PARTIALUPDATEOBJECT
54345453
if create_if_not_exists
54355454
else Action.PARTIALUPDATEOBJECTNOCREATE,
5455+
request_options=request_options,
54365456
)
54375457

54385458
def chunked_batch(

tests/output/python/tests/e2e/insights_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def test_push_events_1(self):
3636
"index": "products",
3737
"userToken": "user-123456",
3838
"authenticatedUserToken": "user-123456",
39-
"timestamp": 1727568000000,
39+
"timestamp": 1727827200000,
4040
"objectIDs": [
4141
"9780545139700",
4242
"9780439784542",
@@ -49,7 +49,7 @@ async def test_push_events_1(self):
4949
"index": "products",
5050
"userToken": "user-123456",
5151
"authenticatedUserToken": "user-123456",
52-
"timestamp": 1727568000000,
52+
"timestamp": 1727827200000,
5353
"objectIDs": [
5454
"9780545139700",
5555
"9780439784542",
@@ -71,7 +71,7 @@ async def test_push_events_1(self):
7171
"index": "products",
7272
"userToken": "user-123456",
7373
"authenticatedUserToken": "user-123456",
74-
"timestamp": 1727568000000,
74+
"timestamp": 1727827200000,
7575
"objectIDs": [
7676
"9780545139700",
7777
"9780439784542",
@@ -84,7 +84,7 @@ async def test_push_events_1(self):
8484
"index": "products",
8585
"userToken": "user-123456",
8686
"authenticatedUserToken": "user-123456",
87-
"timestamp": 1727568000000,
87+
"timestamp": 1727827200000,
8888
"objectIDs": [
8989
"9780545139700",
9090
"9780439784542",
@@ -127,7 +127,7 @@ def test_push_events_1(self):
127127
"index": "products",
128128
"userToken": "user-123456",
129129
"authenticatedUserToken": "user-123456",
130-
"timestamp": 1727568000000,
130+
"timestamp": 1727827200000,
131131
"objectIDs": [
132132
"9780545139700",
133133
"9780439784542",
@@ -140,7 +140,7 @@ def test_push_events_1(self):
140140
"index": "products",
141141
"userToken": "user-123456",
142142
"authenticatedUserToken": "user-123456",
143-
"timestamp": 1727568000000,
143+
"timestamp": 1727827200000,
144144
"objectIDs": [
145145
"9780545139700",
146146
"9780439784542",
@@ -162,7 +162,7 @@ def test_push_events_1(self):
162162
"index": "products",
163163
"userToken": "user-123456",
164164
"authenticatedUserToken": "user-123456",
165-
"timestamp": 1727568000000,
165+
"timestamp": 1727827200000,
166166
"objectIDs": [
167167
"9780545139700",
168168
"9780439784542",
@@ -175,7 +175,7 @@ def test_push_events_1(self):
175175
"index": "products",
176176
"userToken": "user-123456",
177177
"authenticatedUserToken": "user-123456",
178-
"timestamp": 1727568000000,
178+
"timestamp": 1727827200000,
179179
"objectIDs": [
180180
"9780545139700",
181181
"9780439784542",

tests/output/python/tests/requests/insights_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ async def test_push_events_1(self):
463463
"index": "products",
464464
"userToken": "user-123456",
465465
"authenticatedUserToken": "user-123456",
466-
"timestamp": 1727568000000,
466+
"timestamp": 1727827200000,
467467
"objectIDs": [
468468
"9780545139700",
469469
"9780439784542",
@@ -476,7 +476,7 @@ async def test_push_events_1(self):
476476
"index": "products",
477477
"userToken": "user-123456",
478478
"authenticatedUserToken": "user-123456",
479-
"timestamp": 1727568000000,
479+
"timestamp": 1727827200000,
480480
"objectIDs": [
481481
"9780545139700",
482482
"9780439784542",
@@ -491,7 +491,7 @@ async def test_push_events_1(self):
491491
assert _req.query_parameters.items() == {}.items()
492492
assert _req.headers.items() >= {}.items()
493493
assert loads(_req.data) == loads(
494-
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"]}]}"""
494+
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"]}]}"""
495495
)
496496

497497
async def test_push_events_2(self):
@@ -1060,7 +1060,7 @@ def test_push_events_1(self):
10601060
"index": "products",
10611061
"userToken": "user-123456",
10621062
"authenticatedUserToken": "user-123456",
1063-
"timestamp": 1727568000000,
1063+
"timestamp": 1727827200000,
10641064
"objectIDs": [
10651065
"9780545139700",
10661066
"9780439784542",
@@ -1073,7 +1073,7 @@ def test_push_events_1(self):
10731073
"index": "products",
10741074
"userToken": "user-123456",
10751075
"authenticatedUserToken": "user-123456",
1076-
"timestamp": 1727568000000,
1076+
"timestamp": 1727827200000,
10771077
"objectIDs": [
10781078
"9780545139700",
10791079
"9780439784542",
@@ -1088,7 +1088,7 @@ def test_push_events_1(self):
10881088
assert _req.query_parameters.items() == {}.items()
10891089
assert _req.headers.items() >= {}.items()
10901090
assert loads(_req.data) == loads(
1091-
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"]}]}"""
1091+
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"]}]}"""
10921092
)
10931093

10941094
def test_push_events_2(self):

0 commit comments

Comments
 (0)