kragniz / kragniz/python-etcd3
passing an extra keyword to _build_get_range_request doesnt get applied
- Dominant language
- Python
- Stars
- 450
- Forks
- 194
- PR merge metrics
- No merged PRs in 30d
Description
TL;DR: passing an extra keyword to '_build_get_range_request` doesnt get applied. Is this known and should be like this? Or could this be added as a feature?
I wrote the request by hand and the limitations work, and upon closer look I think that the only keywords getting applied to a RangeRequest are `key`, `range_end`, `sort_order`, `sort_target` and `serializable`.
Your source code that handles the section: https://github.com/kragniz/python-etcd3/blob/master/etcd3/client.py#L203 (rows 203-247)
```python
def _build_get_range_request(self, key,
range_end=None,
limit=None,
revision=None,
sort_order=None,
sort_target='key',
serializable=False,
keys_only=False,
count_only=None,
min_mod_revision=None,
max_mod_revision=None,
min_create_revision=None,
max_create_revision=None):
range_request = etcdrpc.RangeRequest()
range_request.key = utils.to_bytes(key)
range_request.keys_only = keys_only
if range_end is not None:
range_request.range_end = utils.to_bytes(range_end)
if sort_order is None:
range_request.sort_order = etcdrpc.RangeRequest.NONE
elif sort_order == 'ascend':
range_request.sort_order = etcdrpc.RangeRequest.ASCEND
elif sort_order == 'descend':
range_request.sort_order = etcdrpc.RangeRequest.DESCEND
else:
raise ValueError('unknown sort order: "{}"'.format(sort_order))
if sort_target is None or sort_target == 'key':
range_request.sort_target = etcdrpc.RangeRequest.KEY
elif sort_target == 'version':
range_request.sort_target = etcdrpc.RangeRequest.VERSION
elif sort_target == 'create':
range_request.sort_target = etcdrpc.RangeRequest.CREATE
elif sort_target == 'mod':
range_request.sort_target = etcdrpc.RangeRequest.MOD
elif sort_target == 'value':
range_request.sort_target = etcdrpc.RangeRequest.VALUE
else:
raise ValueError('sort_target must be one of "key", '
'"version", "create", "mod" or "value"')
range_request.serializable = serializable
return range_request
```
Below is the code I'm currently using that limits the revision to a provided number.
```python
def query_etcd_prefix(self, prefix, revision):
rr = etcd3.etcdrpc.RangeRequest()
rr.key = to_bytes(prefix)
rr.range_end = increment_last_byte(to_bytes(prefix))
rr.sort_order = etcd3.etcdrpc.RangeRequest.NONE
rr.sort_target = etcd3.etcdrpc.RangeRequest.KEY
rr.revision = revision # arbitrary number for testing purposes
range_response = self.__client.kvstub.Range(
rr,
self.__client.timeout,
credentials=client.call_credentials,
metadata=client.metadata
)
if range_response.count < 1:
return None
else:
for kv in range_response.kvs:
yield kv.value, KVMetadata(kv, range_response.header)
```
which shows that just by adding the keyword to the RangeRequest object it gets applied in the executed query.
Could passing extra keywords to any function that creates a etcdrpc.RangeRequest be enabled as a feature or is this not implemented for a reason?
Contributor guide
Research direction
Start in etcd3/client.py around _build_get_range_request, comparing its accepted arguments with the RangeRequest fields shown in the issue. Trace the callers that construct range requests and verify that the requested revision and other supported fields are applied in the executed query without breaking existing behavior.
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
- 35/100