-
Notifications
You must be signed in to change notification settings - Fork 1.2k
loopback.getCurrentContext() not working in a non-http context #982
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
Comments
@BerkeleyTrue could you please provide a test case to reproduce the problem? Ideally using a memory connector. |
This is a problem not specific to bulkUpdate only, it is also a problem when calling model methods from Mocha unit tests (mailing list thread) and strong-mq message listeners (gitter: subscribing to events does not involve a req object, and thus the middleware to initialize the context is not executed. Can you think of any way to read/write the context from within event subscribe (non web context)? Or perhaps there's another construct aside from req context that allows for local storage?) |
I ended up changing the logic to avoid this issue. It would be nice to be able to do this in the future. |
LGTM |
@raymondfeng @ritch what's your opinion on |
@bajtos Why not just use localStorage in the browser? |
I don't understand. Why do you want to persist context in the local storage? How would you provide the default value? Here is what I am thinking about: // browser client
loopback.runInContext(function(context) {
context.set('currentUser', /* data */ });
// start the HTML5 application
}); However, since we don't have continuation-local-storage now, we can make // browser client
loopback.getCurrentContext().set('currentUser', /* data */);
// start the HTML5 application Users can implement whatever persistent mechanism on top of this, for example: var currentUser = localStorage.currentUser ? new User(JSON.parse(localStorage.currentUser)) : null;
loopback.getCurrentContext().set('currentUser', currentUser);
// start the HTML5 app |
We agreed with @raymondfeng and @ritch to keep returning |
I have a need to get the current user during change.rectify() calls after a client calls bulkUpdate.
I have limited understanding of how domains/cls work but it seems that since the juggler is not binded to the current domain/ns anywhere as the req/res objects are, the context is not preserved when the DAO emit's events.
Am I on the right track?
Using loopback 2.8.8
loopback-datasource-juggler 2.12.0
The text was updated successfully, but these errors were encountered: