Read/write bug with list of integers/floats in Python API

14 views
Skip to first unread message

Alex

unread,
May 12, 2011, 5:08:14 PM5/12/11
to scalaris
Hello,

We've noticed something that we think is a bug with the Python API.

If you do a write call with a value that is a list of integers via the
python api and then do a read call on that same key the resultant
object is unicode, not a list. If you do this write/read call with a
list of strings, the resultant object is a list. Here is a sample test
case that has this behavior. Is this to be expected?


>>>x = JSONConnection(url=database)
>>>y= TransactionSingleOp(x)
>>>y.write('xxx', ['1'])
>>>y.read('xxx')
[u'1']
>>>y.write('xxx', ['1','2'])
>>>z=y.read('xxx')
>>>z
[u'1', u'2']
>>>type(z)
<type 'list'>
>>>y.write('xxx', [1,2,3])
>>>z=y.read('xxx')
>>>z

>>>type(z)
<type 'unicode'>
--------------------------------------------------------------------------------
An exception happens when you try with a list of floats:
x = JSONConnection(url=self.database)
y= TransactionSingleOp(x)
y.write('xxx',[1.0,2.0,3.0])
y.read('xxx')

Traceback (most recent call last):
File "/Users/asgillmor/Applications/eclipse/plugins/
org.python.pydev.debug_1.6.3.2010100513/pysrc/pydevd_comm.py", line
685, in doIt
result = pydevd_vars.evaluateExpression(self.thread_id,
self.frame_id, self.expression, self.doExec)
File "/Users/asgillmor/Applications/eclipse/plugins/
org.python.pydev.debug_1.6.3.2010100513/pysrc/pydevd_vars.py", line
369, in evaluateExpression
result = eval(compiled, updated_globals, frame.f_locals)
File "<string>", line 1, in <module>
File "/Users/asgillmor/Documents/nosql/py-tpcc/pytpcc/drivers/api/
Scalaris.py", line 375, in read
result = self._conn.call('read', [key])
File "/Users/asgillmor/Documents/nosql/py-tpcc/pytpcc/drivers/api/
Scalaris.py", line 79, in call
raise ConnectionException(instance)
ConnectionException: ConnectionException()

There is exception on the server as well:
http://pastebin.com/LrdnsJ8M

It should be noted that reading these values via the web interface
looks fine.

Best,
Alex

Thorsten Schuett

unread,
May 16, 2011, 7:51:51 AM5/16/11
to scal...@googlegroups.com
Good catch. In both cases, the json-encoder is screwing up. Florian is
preparing a patch. Both problems should be fixed by the next svn commit.

Thorsten

Nico Kruber

unread,
May 24, 2011, 8:41:42 PM5/24/11
to scal...@googlegroups.com
regarding lists of integers, unfortunately, erlang can _not_ distinguish
between list of (small) integers and strings (which are lists of small
integers, internally). Therefor, we can not guess the resulting type neither
in the Java API, nor in the Python API.
The Java API contains several ***Value() methods for the values read back from
Scalaris.
Since python is dynamically typed, most of these are not needed except for the
conversion from (falsely interpreted) strings to lists of integers.
Use our Scalaris.str_to_list() utility method for this task. You can safely
use it for any integer list (even those with large integers which are already
returned as valid lists). This function will return the original value if it
is not a string or unicode object.

For example, use the following if you are expecting a list:


>>>y.write('xxx', [1,2,3])

>>>z=Scalaris.str_to_list(y.read('xxx'))

Regards,
Nico

signature.asc
Reply all
Reply to author
Forward
0 new messages