Possible bug? where specifying an array with single-quotes gives no results vs double-quotes gives expected results

59 views
Skip to first unread message

Blue Light

unread,
Jan 4, 2017, 6:33:44 PM1/4/17
to ArangoDB
Hi there

Not sure if I'm doing something wrong, but I have a query along the lines of:
FOR d IN collection
FILTER @names_to_lookup ANY in d.possible_names RETURN d

If I specify in the Queries editor names_to_lookup in the single-quotes form:
['name1', 'name2']
then it seems like it's treated as a string instead of an array, and thus I get no results back.

However, when I specify in the Queries editor that names_to_lookup in the double-quotes form:
["name1", "name2"]
then it seems like it's treated as an array (as intended) and I get the expected results back.

I'm not sure if this is a bug or a feature.  While It's easy enough to accept using double quotes in the case of the query editor, this is more problematic for me since I'm relying on the Python-Mango driver where I have less control over the matter and where it seems at least sometimes, a passed-in list comes out in the double-quote form and other times in the single-quote form.

Jan

unread,
Jan 5, 2017, 4:15:28 AM1/5/17
to ArangoDB
The AQL query editor in the web interface expects JSON data for the values entered for bind parameters.
It will JSON-parse each entered value and if that parsing fails (because the value is no valid JSON), it will fall to back to interpreting the value as a string.

The value

  [ "name1", "name2" ]

is valid JSON and will be interpreted as an array with two strings.

The value

  [ 'name1', 'name2' ]

is not valid JSON. The editor will therefore interpret it as a string, i.e.

  "[ 'name1', 'name2' ]"

Regarding the python driver:
All clients/drivers connect to ArangoDB via the HTTP interface, which expects JSON input. I would expect all drivers to just JSON-stringify data when sent to ArangoDB.
So whatever string representation a client-language has (double quotes, single quotes etc.), the language's JSON-stringification should make it work.

For example, in Python:
>>> import json
>>> print json.dumps("foo")
"foo"
>>> print json.dumps('bar')
"bar"

or in JavaScript:
var a = "foo"; // double quotes
var b = 'bar'; // single quotes
JSON.stringify(a); // "foo"
JSON.stringify(b); // "bar"

or in PHP:
$a = "foo"; // double quotes
$b = 'bar'; // double quotes
json_encode($a); // "foo"
json_encode($b); // "bar"

That said, I have no insights into what the Python-Mango driver does, but I would expect it to work with both modes.

Best regards
Jan
Reply all
Reply to author
Forward
0 new messages