dapr / dapr/docs

Incorrect outbox metadata example for Python

Open
#4,506 3 comments 0 reactions 1 assignee Claimed by @elena-kolevska View on GitHub
content/incorrect-information P1
Dominant language
SCSS
Stars
1k
Forks
794
Avg merge
2d 8h
Merged PRs (30d)
7

Description

**Describe the issue**

Example for outbox in python seems to be errored. It assumes we can, via python SDK, do:

```python
await client.state.transaction(DAPR_STORE_NAME, ops);
```

but:
```shell
== APP == c.state.save(
== APP == AttributeError: 'DaprClient' object has no attribute 'state'
```

Indeed python SDK does not provide this `state` attribute.

So I tried:
```python
c.save_state(
store_name=DAPR_STORE_NAME,
key="test",
value='{ "say": "hello world from outbox-metadata" }',
state_metadata={ "outbox.projection": "true" },
metadata=(("outbox.projection", "true"),)
)
```

But despite my efforts in injecting metadatas, I could not see any outbox message in my outbox topic.

Only way I found to get a message in outbox topic is to use transactions:
```python
transaction_operation = TransactionalStateOperation(
operation_type=TransactionOperationType.upsert,
key="1",
data='{ "say": "hello world from outbox transaction" }',
)

c.execute_state_transaction(
store_name=DAPR_STORE_NAME,
operations=[transaction_operation],
transactional_metadata={ 'datacontenttype': 'application/json'},
metadata= (('datacontenttype', 'application/json'),)
)
```

I made this project where you can find full code and logs: https://github.com/jseguillon/dapr-outbox-python

**URL of the docs**

https://github.com/dapr/docs/blob/v1.14/daprdocs/content/en/developing-applications/building-blocks/state-management/howto-outbox.md?plain=1#L205

**Expected content**

A working Python example for outbox with metadata like example for others langages

**Screenshots**

metadata:

![Image](https://github.com/user-attachments/assets/7c4abaac-a8ed-427d-98f2-7e64e7e0bebb)

transaction:

![Image](https://github.com/user-attachments/assets/a998c99e-97f4-43c4-8454-8bbe878f457d)

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.