stashBefore - Invalid query parameter $disableStashBefore
See original GitHub issueSteps to reproduce
Add stashBefore()
to the hooks of a simple service. The code looks like:
const { stashBefore } = require("feathers-hooks-common");
module.exports = {
before: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [stashBefore()],
remove: [stashBefore()]
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
Expected behavior
No errors.
Actual behavior
error: BadRequest: Invalid query parameter $disableStashBefore
at new BadRequest (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/node_modules/@feathersjs/errors/lib/index.js:86:17)
at _.each (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/filter-query.js:48:17)
at Object.keys.forEach.key (<whatever>/node_modules/@feathersjs/commons/lib/utils.js:12:39)
at Array.forEach (<anonymous>)
at Object.each (<whatever>/node_modules/@feathersjs/commons/lib/utils.js:12:24)
at cleanQuery (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/filter-query.js:41:7)
at filterQuery (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/filter-query.js:107:18)
at Object.filterQuery (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/service.js:46:20)
at Object._find (<whatever>/node_modules/feathers-knex/lib/index.js:156:47)
at Object._findOrGet (<whatever>/node_modules/feathers-knex/lib/index.js:224:17)
at Object._get (<whatever>/node_modules/feathers-knex/lib/index.js:228:17)
at callMethod (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/service.js:9:20)
at Object.get (<whatever>/node_modules/feathers-knex/node_modules/@feathersjs/adapter-commons/lib/service.js:56:12)
at processHooks.call.then.hookObject (<whatever>/node_modules/@feathersjs/feathers/lib/hooks/index.js:56:27)
at <anonymous>
Not sure if this is an issue or misconfiguration.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:6 (2 by maintainers)
Top Results From Across the Web
stashBefore - Invalid query parameter $disableStashBefore -
stashBefore - Invalid query parameter $disableStashBefore. ... Add stashBefore() to the hooks of a simple service. The code looks like:
Read more >Writing your own hooks · Feathersjs
$disableStashBefore = true; // delete params.query.$disableStashBefore;. We set a flag to show we are calling the inner get . stashBefore will see the...
Read more >Error "Invalid query parameter $dis " from feathersjs (nodejs ...
I am facing an invalid query parameter error from feathersjs back end . i am using react as front end. My request is...
Read more >Hooks | feathers-hooks-common
Delete the fields from context.params.query . fastJoin #. Join related records. before, after, methods, multi, details ...
Read more >https://raw.githubusercontent.com/feathersjs/feath...
... **Closed issues:** - Wrong lodash imports ... modify stashBefore hook, move $disableStashBefore from query to params ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe the simplest solution to this is to move the
$disableStashBefore
directive out of the query, and up one level intocontext.params
. This sidesteps the query sanitization process while allowing the rest of the functionality to work as expected.https://github.com/feathers-plus/feathers-hooks-common/blob/master/lib/services/stash-before.js#L11
So we replace
with
I’m in agreement with @marshallswain. The proposed API looks like https://feathers-plus.github.io/v1/feathers-hooks-common/#paramsforserver … and thus is not unusual. It also allows us to use stashBefore only on patch for instance. Which helps performance and readability.
As a temporary fix, we should update the doc and mention that you MUST have stashBefore on the
get
before hook, the other placements are optional.Here’s how my patch2Update application hook looks because of this issue:
Here’s how it COULD look with marshall’s fix:
Are we taking PR’s?