Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska committed Nov 4, 2024
1 parent 92639df commit 5e9e02f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion dapr/clients/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ def execute_state_transaction(
transactional_metadata: Optional[Dict[str, str]] = dict(),
metadata: Optional[MetadataTuple] = None,
) -> DaprResponse:

"""Saves or deletes key-value pairs to a statestore as a transaction
This saves or deletes key-values to the statestore as part of a single transaction,
Expand Down
21 changes: 15 additions & 6 deletions examples/state_store/state_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,25 @@
print(f'Got items with etags: {[(i.data, i.etag) for i in items]}')

# Transaction delete
d.execute_state_transaction(store_name=storeName, operations=[
TransactionalStateOperation(operation_type=TransactionOperationType.delete, key=key),
TransactionalStateOperation(operation_type=TransactionOperationType.delete, key=another_key),])
d.execute_state_transaction(
store_name=storeName,
operations=[
TransactionalStateOperation(operation_type=TransactionOperationType.delete, key=key),
TransactionalStateOperation(
operation_type=TransactionOperationType.delete, key=another_key
),
],
)

# Batch get
items = d.get_bulk_state(store_name=storeName, keys=[key, another_key],
states_metadata={'metakey': 'metavalue'}).items
items = d.get_bulk_state(
store_name=storeName, keys=[key, another_key], states_metadata={'metakey': 'metavalue'}
).items
print(f'Got values after transaction delete: {[data.data for data in items]}')

# Delete one state by key.
d.delete_state(store_name=storeName, key=yet_another_key, state_metadata={'metakey': 'metavalue'})
d.delete_state(
store_name=storeName, key=yet_another_key, state_metadata={'metakey': 'metavalue'}
)
data = d.get_state(store_name=storeName, key=yet_another_key).data
print(f'Got value after delete: {data}')
13 changes: 10 additions & 3 deletions tests/clients/test_dapr_grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,16 @@ def test_transaction_then_get_states(self):
self.assertEqual(resp.items[1].key, another_key)
self.assertEqual(resp.items[1].data, to_bytes(another_value.upper()))

dapr.execute_state_transaction(store_name='statestore',
operations=[TransactionalStateOperation(key=key, operation_type=TransactionOperationType.delete),
TransactionalStateOperation(key=another_key, operation_type=TransactionOperationType.delete), ],
dapr.execute_state_transaction(
store_name='statestore',
operations=[
TransactionalStateOperation(
key=key, operation_type=TransactionOperationType.delete
),
TransactionalStateOperation(
key=another_key, operation_type=TransactionOperationType.delete
),
],
)
resp = dapr.get_state(store_name='statestore', key=key)
self.assertEqual(resp.data, b'')
Expand Down

0 comments on commit 5e9e02f

Please sign in to comment.