Skip to content

When validating models, allow unknown keys which are ignored.

Karissa McKelvey requested to merge karissa/pubsweet-server:master into master

Right now, PubSweet sends a 500 Internal Server Error if you try to add a post with the basic setup (pubsweet new, pubsweet run, then navigate to /manage/posts). The error:

info: Saving fragment efbb3aca-96d5-4a30-8212-11e452b48751
info:  ValidationError: "kind" is not allowed. "status" is not allowed
    at Object.exports.process (/Users/karissa/pubsweet-examples/data-science/node_modules/joi/lib/errors.js:181:19)
    at internals.Object._validateWithOptions (/Users/karissa/pubsweet-examples/data-science/node_modules/joi/lib/types/any/index.js:651:31)
    at module.exports.internals.Any.root.validate (/Users/karissa/pubsweet-examples/data-science/node_modules/joi/lib/index.js:121:23)
    at Fragment.validate (/Users/karissa/pubsweet-examples/data-science/node_modules/pubsweet-server/src/models/Model.js:29:26)
    at Fragment.save (/Users/karissa/pubsweet-examples/data-science/node_modules/pubsweet-server/src/models/Model.js:42:10)
    at Authorize.can.then.then.collection (/Users/karissa/pubsweet-examples/data-science/node_modules/pubsweet-server/src/routes/api_collections.js:135:21)
    at <anonymous>

It seems like pubsweet-component-post-manager is sending along 'kind' and 'status' on these lines https://gitlab.coko.foundation/pubsweet/pubsweet-components/blob/master/packages/PostsManager/PostCreator.jsx#L19-23

So either this component needs to be edited to reflect the new state of the pubsweet-server backend, the backend needs to have these two fields added to the fragment, or we just allow the client to send extra values without validation.

I'm not sure where this bug was introduced or where a test could be added for it. Are there integration tests that test the frontend components and server together?

Since PubSweet is in a fairly early version, I opted here to allow extra unknown keys, in case there were other models that didn't have the correct validation schema.

Merge request reports