Subject: | Bug in AnyEvent-CouchDB-1.28: Cannot use plain integer keys when querying views |
Date: | Wed, 7 Mar 2012 16:04:02 +0100 |
To: | bug-AnyEvent-CouchDB [...] rt.cpan.org |
From: | Daniel Westerberg <daniel.westerberg [...] diino.net> |
Distribution: AnyEvent-CouchDB-1.28
Perl version: v5.8.8 built for x86_64-linux-thread-multi
OS: Linux 2.6.24-12-pve #1 SMP PREEMPT Mon Sep 20 13:02:41 CEST 2010 x86_64
x86_64 x86_64 GNU/Linux
Hello!
First of all thanks for a great library!
I am experiencing some problems when trying to query a view that uses plain
integers as keys.
These are my example documents and their corresponding keys:
Show quoted text
> *curl '
http://localhost:5984/laplace_stats_development/_design/RecentUserQuota/_view/by_uid
'*
{"total_rows":8,"offset":1,"rows":[
{"id":"24f21fb5595c4ab3ab1e8c382f778fc3","key":172,"value":null},
{"id":"24f21fb5595c4ab3ab1e8c382f77a028","key":171,"value":null},
{"id":"24f21fb5595c4ab3ab1e8c382fb4eaa2","key":173,"value":null},
{"id":"24f21fb5595c4ab3ab1e8c382fb507f4","key":173,"value":null},
{"id":"506953a41dc3ee5b893a5e061c7bdf63","key":171,"value":null},
{"id":"506953a41dc3ee5b893a5e061cf94563","key":172,"value":null},
{"id":"506953a41dc3ee5b893a5e061cf96171","key":171,"value":null}
]}
I cam query the view manually without any problems using an integer as a
key:
Show quoted text> *curl '
http://localhost:5984/laplace_stats_development/_design/RecentUserQuota/_view/by_uid
?key=171'*
{"total_rows":8,"offset":1,"rows":[
{"id":"24f21fb5595c4ab3ab1e8c382f77a028","key":171,"value":null},
{"id":"506953a41dc3ee5b893a5e061c7bdf63","key":171,"value":null},
{"id":"506953a41dc3ee5b893a5e061cf96171","key":171,"value":null}
]}
However when I try to do this in perl using AnyEvent::CouchDB I am unable
to query the view with an integer key without it being converted to a
string. I guess this is due to the following code on lines 30-34 in
AnyEvent::CouchDB::Database:
if ($name eq 'key' || $name eq 'startkey' || $name eq 'endkey') {
$value = ref($value)
? uri_escape($json->encode($value))
: (defined $value)
? uri_escape_utf8(qq{"$value"})
: 'null';
This clearly shows that if the value used for the key is not a complex one (
ref($value)) it is converted to a string (qq{"$value"}). If it however is a
complex value it is converted to json using a json encoder. This makes my
call instead equivalent to:
Show quoted text> *curl '
http://localhost:5984/laplace_stats_development/_design/RecentUserQuota/_view/by_uid
?key="171"'*
{"total_rows":8,"offset":1,"rows":[]}
This is not correct and needs to be fixed as this is not an expected
behaviour.
Once again, thank you for a very nice library! Besides this everything
seems to work beautifully :)
Best regards,
Daniel Westerberg