question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

stashBefore - Invalid query parameter $disableStashBefore

See original GitHub issue

Steps 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:open
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
marshallswaincommented, Aug 3, 2019

I believe the simplest solution to this is to move the $disableStashBefore directive out of the query, and up one level into context.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

params.query.$disableStashBefore

with

params.$disableStashBefore
1reaction
FossPrimecommented, Sep 27, 2019

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:

import patch2Update from './hooks/patch2Update.js'
import { discardQuery } from 'feathers-hooks-common'

export default {
  before: {
    get: [ discardQuery('$disableStashBefore') ],
    patch: [ patch2Update() ]
  }
}

Here’s how it COULD look with marshall’s fix:

import patch2Update from './hooks/patch2Update.js'

export default {
  before: {
    patch: [ patch2Update() ]
  }
}

Are we taking PR’s?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found