pouchdb validation rules don't work in pouch AND couch
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 validateDocUpda
if (newDoc._id === "myid") {
throw {"forbidden": "Mine!!!"};
}
}
and use that in the design view
validate_
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 validateDocUpda
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.
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!