basho / riak-python-client

The Riak client for Python.
Apache License 2.0
320 stars 182 forks source link

Error when generating object keys [JIRA: CLIENTS-900] #484

Open linkdd opened 8 years ago

linkdd commented 8 years ago

Using riak 2.1.4 with the python client 2.5.3 with Python 3.4.3:

from riak import RiakClient

c = RiakClient(nodes=[{
    'host': '127.0.0.1',
    'pb_port': '8087'
}])

maps = c.bucket_type('maps')

nodes = maps.bucket('nodes')

node = nodes.new()  # expecting key to be generated by riak
# ...
node.store()

It seems that the generated key is of type bytes instead of str in Python3:

Traceback (most recent call last):
  File "graph.py", line 77, in <module>
    node.store()
  File "/home/linkdd/devel/projects/link-framework/venv3/lib/python3.4/site-packages/riak/datatypes/datatype.py", line 165, in update
    self.bucket._client.update_datatype(self, **params)
  File "/home/linkdd/devel/projects/link-framework/venv3/lib/python3.4/site-packages/riak/client/operations.py", line 1143, in update_datatype
    include_context=include_context)
  File "/home/linkdd/devel/projects/link-framework/venv3/lib/python3.4/site-packages/riak/transports/tcp/transport.py", line 505, in update_datatype
    msg = codec.encode_update_datatype(datatype, **kwargs)
  File "/home/linkdd/devel/projects/link-framework/venv3/lib/python3.4/site-packages/riak/codecs/pbuf.py", line 1211, in encode_update_datatype
    req.key = str_to_bytes(datatype.key)
  File "/home/linkdd/devel/projects/link-framework/venv3/lib/python3.4/site-packages/riak/util.py", line 118, in str_to_bytes
    return value.encode(encoding)
AttributeError: 'bytes' object has no attribute 'encode'
lukebakken commented 8 years ago

Hello -

Could you please run this command and provide the output in a response?

riak-admin bucket-type status maps

Thanks. I'd like to see how the maps bucket type is configured.

linkdd commented 8 years ago

Here is the output:

maps is active

young_vclock: 20
w: quorum
small_vclock: 50
rw: quorum
r: quorum
pw: 0
precommit: []
pr: 0
postcommit: []
old_vclock: 86400
notfound_ok: true
n_val: 3
linkfun: {modfun,riak_kv_wm_link_walker,mapreduce_linkfun}
last_write_wins: false
dw: quorum
dvv_enabled: true
chash_keyfun: {riak_core_util,chash_std_keyfun}
big_vclock: 50
basic_quorum: false
allow_mult: true
datatype: map
active: true
claimant: 'riak@127.0.0.1'

FYI, I followed the documentation when creating the bucket:

$ riak-admin bucket-type create maps '{"props":{"datatype":"map"}}'
$ riak-admin bucket-type activate maps
lukebakken commented 8 years ago

OK. I asked because there is an integration test that tests a Riak-generated key on a non-datatype bucket, but I couldn't find something for a bucket configured for a datatype. I suspect that's the issue.