Skip to content

Commit 278ba8d

Browse files
Merge branch 'main' into mock-actors-3
2 parents e17a85b + b97d68f commit 278ba8d

File tree

8 files changed

+50
-10
lines changed

8 files changed

+50
-10
lines changed

.github/workflows/build-push-to-main.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
tox -e py`echo "${{ matrix.python_ver }}" | sed 's/\.//g'`
6060
- name: Upload test coverage
61-
uses: codecov/codecov-action@v4
61+
uses: codecov/codecov-action@v5
6262
publish:
6363
needs: build
6464
if: github.event_name != 'pull_request'

.github/workflows/build-tag.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: |
6262
tox -e py`echo "${{ matrix.python_ver }}" | sed 's/\.//g'`
6363
- name: Upload test coverage
64-
uses: codecov/codecov-action@v4
64+
uses: codecov/codecov-action@v5
6565
publish:
6666
needs: build
6767
if: github.event_name != 'pull_request'

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
run: |
6565
tox -e py`echo "${{ matrix.python_ver }}" | sed 's/\.//g'`
6666
- name: Upload test coverage
67-
uses: codecov/codecov-action@v4
67+
uses: codecov/codecov-action@v5

dapr/clients/grpc/_request.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class TransactionalStateOperation:
281281
def __init__(
282282
self,
283283
key: str,
284-
data: Union[bytes, str],
284+
data: Optional[Union[bytes, str]] = None,
285285
etag: Optional[str] = None,
286286
operation_type: TransactionOperationType = TransactionOperationType.upsert,
287287
):
@@ -297,7 +297,7 @@ def __init__(
297297
Raises:
298298
ValueError: data is not bytes or str.
299299
"""
300-
if not isinstance(data, (bytes, str)):
300+
if operation_type != TransactionOperationType.delete and not isinstance(data, (bytes, str)):
301301
raise ValueError(f'invalid type for data {type(data)}')
302302

303303
self._key = key
@@ -311,7 +311,7 @@ def key(self) -> str:
311311
return self._key
312312

313313
@property
314-
def data(self) -> Union[bytes, str]:
314+
def data(self) -> Union[bytes, str, None]:
315315
"""Gets raw data."""
316316
return self._data
317317

dapr/clients/grpc/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def execute_state_transaction(
933933
operationType=o.operation_type.value,
934934
request=common_v1.StateItem(
935935
key=o.key,
936-
value=to_bytes(o.data),
936+
value=to_bytes(o.data) if o.data is not None else to_bytes(''),
937937
etag=common_v1.Etag(value=o.etag) if o.etag is not None else None,
938938
),
939939
)

examples/state_store/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ expected_stdout_lines:
4141
- "== APP == Cannot save bulk due to bad etags. ErrorCode=StatusCode.ABORTED"
4242
- "== APP == Got value=b'value_1' eTag=1"
4343
- "== APP == Got items with etags: [(b'value_1_updated', '2'), (b'value_2', '2')]"
44+
- "== APP == Got values after transaction delete: [b'', b'']"
4445
- "== APP == Got value after delete: b''"
4546
timeout_seconds: 5
4647
-->
@@ -67,6 +68,8 @@ The output should be as follows:
6768
6869
== APP == Got items with etags: [(b'value_1_updated', '2'), (b'value_2', '2')]
6970
71+
== APP == Got values after transaction delete: [b'', b'']
72+
7073
== APP == Got value after delete: b''
7174
```
7275

examples/state_store/state_store.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
etag=state.etag,
7979
),
8080
TransactionalStateOperation(key=another_key, data=another_value),
81+
TransactionalStateOperation(key=yet_another_key, data=yet_another_value),
8182
],
8283
)
8384

@@ -87,7 +88,26 @@
8788
).items
8889
print(f'Got items with etags: {[(i.data, i.etag) for i in items]}')
8990

91+
# Transaction delete
92+
d.execute_state_transaction(
93+
store_name=storeName,
94+
operations=[
95+
TransactionalStateOperation(operation_type=TransactionOperationType.delete, key=key),
96+
TransactionalStateOperation(
97+
operation_type=TransactionOperationType.delete, key=another_key
98+
),
99+
],
100+
)
101+
102+
# Batch get
103+
items = d.get_bulk_state(
104+
store_name=storeName, keys=[key, another_key], states_metadata={'metakey': 'metavalue'}
105+
).items
106+
print(f'Got values after transaction delete: {[data.data for data in items]}')
107+
90108
# Delete one state by key.
91-
d.delete_state(store_name=storeName, key=key, state_metadata={'metakey': 'metavalue'})
92-
data = d.get_state(store_name=storeName, key=key).data
109+
d.delete_state(
110+
store_name=storeName, key=yet_another_key, state_metadata={'metakey': 'metavalue'}
111+
)
112+
data = d.get_state(store_name=storeName, key=yet_another_key).data
93113
print(f'Got value after delete: {data}')

tests/clients/test_dapr_grpc_client.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from .fake_dapr_server import FakeDaprSidecar
3434
from dapr.conf import settings
3535
from dapr.clients.grpc._helpers import to_bytes
36-
from dapr.clients.grpc._request import TransactionalStateOperation
36+
from dapr.clients.grpc._request import TransactionalStateOperation, TransactionOperationType
3737
from dapr.clients.grpc._state import StateOptions, Consistency, Concurrency, StateItem
3838
from dapr.clients.grpc._crypto import EncryptOptions, DecryptOptions
3939
from dapr.clients.grpc._response import (
@@ -508,6 +508,23 @@ def test_transaction_then_get_states(self):
508508
self.assertEqual(resp.items[1].key, another_key)
509509
self.assertEqual(resp.items[1].data, to_bytes(another_value.upper()))
510510

511+
dapr.execute_state_transaction(
512+
store_name='statestore',
513+
operations=[
514+
TransactionalStateOperation(
515+
key=key, operation_type=TransactionOperationType.delete
516+
),
517+
TransactionalStateOperation(
518+
key=another_key, operation_type=TransactionOperationType.delete
519+
),
520+
],
521+
)
522+
resp = dapr.get_state(store_name='statestore', key=key)
523+
self.assertEqual(resp.data, b'')
524+
525+
resp = dapr.get_state(store_name='statestore', key=another_key)
526+
self.assertEqual(resp.data, b'')
527+
511528
self._fake_dapr_server.raise_exception_on_next_call(
512529
status_pb2.Status(code=code_pb2.INVALID_ARGUMENT, message='my invalid argument message')
513530
)

0 commit comments

Comments
 (0)