Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

KV value is returned in bytes rather than string when using Python 3  #172

@roman-vynar

Description

@roman-vynar

consul_api.kv.get() is supposed to return:

                {
                    "CreateIndex": 100,
                    "ModifyIndex": 200,
                    "LockIndex": 200,
                    "Key": "foo",
                    "Flags": 0,
                    "Value": "bar",
                    "Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
                }

It is true for Python 2.
When using Python 3, there is a minor difference for Value field:

                    "Value": b'bar',

which is bytes, not a string.

Thus, it makes Ansible consul_kv module, for example, not working properly as it badly compares string value coming from consul_api.kv.get():

>>> b'abc' == 'abc'
False

Suggestion: to return value as a string to make it working for Python 3 the same way as for 2.

>>> b'abc'.decode() == 'abc'
True

I am sure noone is going to put b'text' as a value into Consul KV as it will be stored exactly that way which seems to be a garbage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions