pouchdb validation rules don't work in pouch AND couch

Bug #1380910 reported by Steve Ryan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python-PouchDB
Won't Fix
Low
Marten de Vries

Bug Description

In the examples for pouchdb validation plugin you define a function

function validateDocUpdateTest(newDoc, oldDoc, userCtx, secObj) {
  if (newDoc._id === "myid") {
    throw {"forbidden": "Mine!!!"};
  }
}

and use that in the design view

validate_doc_update: validateDocUpdateTest.toString()

which works fine locally in pouch for validation but when the design rule is synced to a couchdb server, it becomes impossible to save anything in futon because couch complains that "Error: compilation error. Expression does not eval to a function"
--------------------------------------------------
However if I define the validation function as a variable ie

var validateDocUpdateTest = function(newDoc, oldDoc, userCtx, secObj) {
  if (newDoc._id === "myid") {
    throw {"forbidden": "Mine!!!"};
  }
}

Then all is well and the validation function works both locally and inside couch.

I would have thought that defining a function as a variable or in the traditional way would make to difference to the face that validateDocUpdate is a function object but toString on the function includes the name of the function whereas toString on the variable version does not and everything is OK. Wierd.
------------------------------------------------------------------------------
End of the day, might be worth updating your documentation to use the variable version so that things work client and server.

Revision history for this message
Marten de Vries (marten-de-vries) wrote :

I think the problem is that CouchDB expects an expression and gets a statement, where in the browser because of a slightly different context, the statement is converted to an expression.

Anyway, I agree it's confusing and that the documentation should just use the 'var ... = function () {}' form you described. Will change it before the next version.

Thanks for reporting!

Changed in python-pouchdb:
status: New → Triaged
importance: Undecided → Low
assignee: nobody → Marten de Vries (marten-de-vries)
milestone: none → 0.5
Revision history for this message
Marten de Vries (marten-de-vries) wrote :
Changed in python-pouchdb:
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.