kragniz / kragniz/python-etcd3

return revision when put_if_not_exists() succeed

Open
#1,648 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
450
Forks
194
PR merge metrics
No merged PRs in 30d

Description

Current implement of put_if_not_exists() only return bool indicate succeed or not, I think it's make more useful to return revision of key, for example, after put_if_not_exits(KEY), user add watch of KEY to monitor if it's been delete or not. without revision, it always has the chance that the next watch call didn't catch all event since PUT, unless use revision as parameter.

with revision, a better user code can be write as
```
status,revision = put_if_not_exists(client,KEY,VALUE)
# delay can happen between two calls
client.add_watch_callback(TEST_KEY,watch_cb,start_revision=revision+1)
```
I tried to write my own impl, but it end with unwrap RPC message layers, (resp.response_put.header.revision) not quite good.

```
def put_if_not_exists(client, key, value, lease=None):
status, responses = client.transaction(
compare=[
client.transactions.version(key) == 0
],
success=[
client.transactions.put(key, value, lease)
],
failure=[],
)
revision = 0
if status:
for resp in responses:
revision = resp.response_put.header.revision
return status, revision
```

Contributor guide

Open the contributing guide

Research direction

Start at the put_if_not_exists() entry point and trace the client.transaction() responses, especially response_put.header.revision. Done means a successful call exposes the transaction revision alongside its status, while failure behavior remains defined for callers using the watch start_revision value.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.