couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "richard delorenzi (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COUCHDB-2204) rewrite of lists fail when not for key
Date Wed, 19 Mar 2014 19:19:43 GMT

    [ https://issues.apache.org/jira/browse/COUCHDB-2204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13940873#comment-13940873
] 

richard delorenzi commented on COUCHDB-2204:
--------------------------------------------

Adding the new formats record as you show would help, at least I could get it to work. However
I think it is a bug to be able to pass a list to startkey, endkey etc, but not to other variables.

I spend an hours trying to get it to work, then checked that my code was the same as when
it worked before (using start/end key), then changing just "startkey" to "s" and it stops
working as expected. Then checking the couch source code, to discover that it was not me,
it was an inconsistency in the code. Internal inconsistencies are bad, and I imagine it has
tripped over other programmers. The best fix would be to remove the inconsistency. Doing that
while keeping it backward compatible I will leave to you. For now, as my paths are always
2 long, I will store the 2 parts in two variables "~dir" and "~name".

Thanks,
Richard

> rewrite of lists fail when not for key
> --------------------------------------
>
>                 Key: COUCHDB-2204
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2204
>             Project: CouchDB
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: HTTP Interface
>            Reporter: richard delorenzi
>
> I have the following fragment in rewrite.json, 
> {code:javascript|title=this rewrite.json does not work}
> { 
> 	"from": "server_lib/:~name",
> 	"to": "_list/sub/design",
> 	"query": {
> 	    "path": ["lib", ":~name" ]
> 	}
> }
> {code}
> when I try to fetch the page with
> {code: title=http get}
> curl  -s -D /dev/stderr -H "Accept: application/json" 'http://localhost:5984/q-couch-test/_design/couch-experiment/_rewrite/server_lib/myLib'
> {code}
> I get this error
> {code: title=error}
> log error:
> [Tue, 18 Mar 2014 09:54:31 GMT] [info] [<0.5037.0>] Stacktrace: [{erlang,iolist_to_binary,
>                                      [[<<"myLib">>,{[]}]],
>                                      []},
>                                  {couch_httpd_rewrite,
>                                      '-maybe_encode_bindings/1-fun-0-',2,
>                                      [{file,"couch_httpd_rewrite.erl"},
>                                       {line,453}]},
>                                  {lists,foldl,3,
>                                      [{file,"lists.erl"},{line,1197}]},
>                                  {couch_httpd_rewrite,handle_rewrite_req,3,
>                                      [{file,"couch_httpd_rewrite.erl"},
>                                       {line,147}]},
>                                  {couch_httpd_db,do_db_req,2,
>                                      [{file,"couch_httpd_db.erl"},{line,230}]},
>                                  {couch_httpd,handle_request_int,5,
>                                      [{file,"couch_httpd.erl"},{line,317}]},
>                                  {mochiweb_http,headers,5,
>                                      [{file,"mochiweb_http.erl"},{line,136}]},
>                                  {proc_lib,init_p_do_apply,3,
>                                      [{file,"proc_lib.erl"},{line,227}]}]
> {code}
> The bug seems to be in couch_httpd_rewrite.erl in maybe_json. It treats keys specially,
so we can represent keys as lists but not other query strings.
> e.g. this rewrite fragment works
> {code: javascript|title=working rewrite.json example}
>  { 
> 	"from": "view/by_name/:~type",
> 	"to":  "_view/all-by-name",
> 	"query": { 
> 	    "startkey": [ ":~type", null ],
> 	    "endkey":   [ ":~type", {} ]
> 	} 
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message