Skip to content

Commit a082156

Browse files
committed
Updates for tests and error handling
1 parent 5b07963 commit a082156

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

key-value/key-value-aio/src/key_value/aio/stores/elasticsearch/store.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,13 @@ async def _put_managed_entries(
354354
)
355355

356356
operations.extend([index_action, document])
357-
358-
_ = await self._client.bulk(operations=operations, refresh=self._should_refresh_on_put) # pyright: ignore[reportUnknownMemberType]
357+
try:
358+
_ = await self._client.bulk(operations=operations, refresh=self._should_refresh_on_put) # pyright: ignore[reportUnknownMemberType]
359+
except ElasticsearchSerializationError as e:
360+
msg = f"Failed to serialize bulk operations: {e}"
361+
raise SerializationError(message=msg) from e
362+
except Exception:
363+
raise
359364

360365
@override
361366
async def _delete_managed_entry(self, *, key: str, collection: str) -> bool:

key-value/key-value-aio/src/key_value/aio/stores/elasticsearch/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_aggregations_from_body(body: dict[str, Any]) -> dict[str, Any]:
3737
if not isinstance(aggregations, dict) or not all(
3838
isinstance(key, str)
3939
for key in aggregations # pyright: ignore[reportUnknownVariableType]
40-
): # pyright: ignore[reportUnknownVariableType]
40+
):
4141
return {}
4242

4343
return cast("dict[str, Any]", aggregations)

key-value/key-value-aio/tests/stores/redis/test_redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_managed_entry_document_conversion():
3636
document = managed_entry_to_json(managed_entry=managed_entry)
3737

3838
assert document == snapshot(
39-
'{"value": {"test": "test"}, "created_at": "2025-01-01T00:00:00+00:00", "expires_at": "2025-01-01T00:00:10+00:00"}'
39+
'{"created_at": "2025-01-01T00:00:00+00:00", "expires_at": "2025-01-01T00:00:10+00:00", "value": {"test": "test"}}'
4040
)
4141

4242
round_trip_managed_entry = json_to_managed_entry(json_str=document)

key-value/key-value-sync/src/key_value/sync/code_gen/stores/elasticsearch/store.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,13 @@ def _put_managed_entries(
303303
)
304304

305305
operations.extend([index_action, document])
306-
307-
_ = self._client.bulk(operations=operations, refresh=self._should_refresh_on_put) # pyright: ignore[reportUnknownMemberType]
306+
try:
307+
_ = self._client.bulk(operations=operations, refresh=self._should_refresh_on_put) # pyright: ignore[reportUnknownMemberType]
308+
except ElasticsearchSerializationError as e:
309+
msg = f"Failed to serialize bulk operations: {e}"
310+
raise SerializationError(message=msg) from e
311+
except Exception:
312+
raise
308313

309314
@override
310315
def _delete_managed_entry(self, *, key: str, collection: str) -> bool:

key-value/key-value-sync/src/key_value/sync/code_gen/stores/elasticsearch/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def get_aggregations_from_body(body: dict[str, Any]) -> dict[str, Any]:
3232
return {}
3333

3434
if not isinstance(aggregations, dict) or not all(isinstance(key, str) for key in aggregations): # pyright: ignore[reportUnknownVariableType]
35-
# pyright: ignore[reportUnknownVariableType]
3635
return {}
3736

3837
return cast("dict[str, Any]", aggregations)

key-value/key-value-sync/tests/code_gen/stores/redis/test_redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_managed_entry_document_conversion():
3636
document = managed_entry_to_json(managed_entry=managed_entry)
3737

3838
assert document == snapshot(
39-
'{"value": {"test": "test"}, "created_at": "2025-01-01T00:00:00+00:00", "expires_at": "2025-01-01T00:00:10+00:00"}'
39+
'{"created_at": "2025-01-01T00:00:00+00:00", "expires_at": "2025-01-01T00:00:10+00:00", "value": {"test": "test"}}'
4040
)
4141

4242
round_trip_managed_entry = json_to_managed_entry(json_str=document)

0 commit comments

Comments
 (0)