python-consul2
python-consul2 copied to clipboard
Unable to differentiate non-existent and empty keys in KV store
On the consul API if I query an existing endpoint for keys, I receive an empty list, whereas if I query a non-existent key, I receive HTTP 404.
Using the python library, however, I can't differentiate the two cases.
Examples
Existing but empty
$ curl http://.../v1/kv/?keys=True -v
...
> GET /v1/kv/?keys=True HTTP/1.1
...
< HTTP/1.1 200 OK
< Content-Type: application/json
< Vary: Accept-Encoding
< X-Consul-Default-Acl-Policy: allow
< X-Consul-Index: 74726
< X-Consul-Knownleader: true
< X-Consul-Lastcontact: 0
< X-Consul-Query-Backend: blocking-query
< Date: Thu, 03 Nov 2022 16:08:47 GMT
< Content-Length: 2
...
[]
>>> c.kv.get('', keys=True)
('74726', None)
Not existing
$ curl http://.../v1/kv/s/?keys=True -v
...
> GET /v1/kv/s/?keys=True HTTP/1.1
...
< HTTP/1.1 404 Not Found
< Vary: Accept-Encoding
< X-Consul-Default-Acl-Policy: allow
< X-Consul-Index: 74726
< X-Consul-Knownleader: true
< X-Consul-Lastcontact: 0
< X-Consul-Query-Backend: blocking-query
< Date: Thu, 03 Nov 2022 16:08:41 GMT
< Content-Length: 0
>>> c.kv.get('s/', keys=True)
('74726', None)
I have investigated the issue. It was introduced in 6f4eb97 where the meaningless map was replaced (exact change: https://github.com/poppyred/python-consul2/commit/6f4eb974227cb91a4f9d7496adfc030fa6e07284#diff-87d94b41a52bb393bfca3dc4b47be3807560585a919ef66394f9fe6e20c216c2R2899). The commit doesn't include reasoning, but I think that was a mistake. In this case, the api returns an empty list, which is very different from a None. And this difference is necessary.