-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Previous document is lost inside async callbacks #103
Comments
Here is simpler example that just uses Meteor.defer and no calls to npm packages:
|
I want confirm the bug. it's very strange, it happens irregular see output: I20150318-10:31:29.968(1)? triggerUpdate fired I20150318-10:31:34.530(1)? triggerUpdate fired I also confirm, that in normal (sync) mode it works normally |
Looks like the same happens when Meteor.setInterval is used. As far as I know "Meteor.defer", "Meteor.setInterval" and "Meteor.setTimeout" use "Meteor.bindEnvironment" under the hood, so looks like previous document is lost somewhere in that "environment" |
Am 18.03.15 um 16:02 schrieb atoi:
@matb33 do you have an idea what the issue there is, maybe we then could |
This really does look like a bug, and odds are it's a collection-hooks problem with bindEnvironment as you suspect. I don't have the time to look at it now but it's on the list for sure. |
Two environment variables we use are for the https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js Would any of those affect the operation here? |
I was looking through this as this error showed up for me today today. If I just console.log the value of A non elegant solution that worked for me is to locally patch the project by just passing the previous doc into the function. This doesn't solve the issue for the repo unfortunately because this doesn't change the issue that your caller is now global. But for anyone who has this issue as a blocker you can clone the repo and change line 72 in update to this:
This really confuses me as I can see you are passing an inline object as the first arguement of call here. I console logged the result and this is a valid object being returned in my case. If anyone else has any theories I wouldn't mind helping but I needed a solution for the prev object atm (deadlines 😦 ). So I didn't get to dig any deeper into the code as I'm unfamiliar with the project as a whole. |
@matb33 I read from a couple other posts you are not finding much time to spend on this repo lately. I just wanted to ask (whenever you have time) If you would consider a hotfix patch where you just passed the previous document in as a temp solution. Or if you could guide a bit on where you would imagine the context of this is being lost in this case. Thanks for your time. |
Sometimes in "after.update" hook the value of "this.previous" document is undefined. That happens when you make an update call inside a callback, wrapped with bindEnvironment.
I provided a simple example to see the issue. Just call "generateComments" method and take a look at your server console. You'll see something like this:
The code below will work in meteor 1.0.4 only as it uses "rawCollection" method to run bulk insert.
Trust me, the same issue happens in meteor 1.0.3.2 when I use mongo npm to run bulk inserts.
I just did not want to bloat the example.
Example code:
The text was updated successfully, but these errors were encountered: