meteor-collection-hooks icon indicating copy to clipboard operation
meteor-collection-hooks copied to clipboard

before.insert won't run before collection2 schema check on server side when calling via method

Open DaxChen opened this issue 9 years ago • 6 comments

Hi, @matb33

Here's a repo to reproduce the error

When inserting inside meteor method, only client side runs the before.insert hook before collection2 's schema check. Server side won't run the hook, and fails the schema check. Error message:

Exception while invoking method 'insertTest' Error: Created at is required
I20151123-01:04:26.343(8)?     at getErrorObject (packages/aldeed_collection2/packages/aldeed_collection2.js:425:1)
I20151123-01:04:26.343(8)?     at [object Object].doValidate (packages/aldeed_collection2/packages/aldeed_collection2.js:408:1)
I20151123-01:04:26.343(8)?     at [object Object].Mongo.Collection.(anonymous function) [as insert] (packages/aldeed_collection2/packages/aldeed_collection2.js:177:1)
I20151123-01:04:26.343(8)?     at [object Object].Meteor.methods.insertTest (collection-hook-serverside-test.js:33:12)
I20151123-01:04:26.343(8)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151123-01:04:26.343(8)?     at livedata_server.js:708:19
I20151123-01:04:26.343(8)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)?     at livedata_server.js:706:40
I20151123-01:04:26.344(8)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)?     at livedata_server.js:704:46
I20151123-01:04:26.344(8)? Sanitized and reported to the client as: Created at is required [400]

Am I doing something wrong? Or is this a bug?

Thanks! YuHuaiChen

DaxChen avatar Nov 22 '15 17:11 DaxChen

Looks like a load order issue. See https://github.com/matb33/meteor-collection-hooks/issues/153

huevoncito avatar Dec 23 '15 19:12 huevoncito

Unfortunately, changing the order of the dependencies inside my package doesn't fix this. Anyone have another workaround? Not being able to use collection-hooks and collection2 together in Meteor methods would lead to a pretty significant setback in the app I'm working on.

beverlycodes avatar Feb 15 '16 20:02 beverlycodes

@ryanfields did you figure this out?

@huevoncito it's definitely not a load order

yogiben avatar Apr 12 '16 14:04 yogiben

@yogiben Nope. I've stopped using collection-hooks. I didn't really find any good alternatives though. I just do what I can to work around the need for hooks now.

beverlycodes avatar Apr 12 '16 15:04 beverlycodes

Looks like schemas/hooks order is inverted between client and server side: #154.

nicooprat avatar Jun 02 '16 16:06 nicooprat