incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Suspected view generator bug...
Date Fri, 19 Feb 2010 13:12:13 GMT
Patrick,

You are exactly right. Previously we would freeze the document object
to prevent functions from modifying it, but that function was broken
in Spidermonkey so it was disabled. In the future if that's ever fixed
we'll reenable it.

HTH,
Paul Davis

On Fri, Feb 19, 2010 at 12:30 AM, Patrick Barnes <mrtrick@gmail.com> wrote:
> I was tearing my hair out because this view:
>
> map: function(doc) {
>        if (doc.doc_type=='group') {
>                doc.path.pop();
>                emit(doc.path, doc.display_name);
>        }
> }
>
> Was supposed to take one element off the end of the path array and using the
> array as a view key. However, when I triggered view creation it would remove
> TWO elements!
>
> Strangely, if I opened the view function from within futon, added some
> whitespace and re-ran the function it worked fine.
>
> There are two similar views that both use the doc.path.pop() call.
> I'm fairly confident that behind the scenes, the couchdb (trunk) view
> generator is
> a) sharing a single copy of each document between all the map functions.
> b) permitting map functions to modify that copy, meaning that subsequent map
> functions might get a CORRUPTED version of the document.
>
> Verdict?
>
> For now, I've rewritten my map functions to clone the array to a local var
> before I call path.pop().
>
> -Patrick Barnes
>

Mime
View raw message