-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
fix(core,microservices): inject the context when the tree is not durable #10809
fix(core,microservices): inject the context when the tree is not durable #10809
Conversation
Pull Request Test Coverage Report for Build eb39fb09-4213-4d70-b662-1e7d6091c253
💛 - Coveralls |
82518f4
to
dda7ded
Compare
@micalevisk I've created a small test for this but it seems to be working as expected in the most recent nest master branch. Code here https://github.com/vizio360/nest/pull/1/files Unless I misunderstood the problem. |
Actually I didn't really test it properly. I've not set up the And maybe I should start with your test first :) |
Ok, cloned the repo, ran
that is without your patch applied and nestjs core Am I doing something wrong? |
@vizio360 did you use the branch |
Just tested it with main and it seems to work. But the branch of your repo should not really matter as nestjs is installed as an npm.
|
@vizio360 the branch do matter as one has a patch that will be applied after git clone -b main https://gitlab.com/micalevisk/nestjs-bug-pr-10793
cd nestjs-bug-pr-10793
npm ci # even using npm i will reproduce the same
npm start
./request.sh foo
{"is_req_defined":false} this is what I got on linux rn. Pretty weird 🤔 |
Oh ok, did not know it would automagically apply the patch (never used that before). And sorry I've been switching context too many times and I see what I have done wrong... I was running the patched nestjs app from the other repo and the request script from the main repo. Apologies. Doing it again now. |
@micalevisk yeap same result. simone.vicentini@Simones-MacBook-Pro ~/dev/repos/vizio360/nestjs-bug-pr-10793-main [11:40:24]
> $ ./request.sh test ⬡ 16.13.2 [±main ✓]
{"is_req_defined":false}% Will properly look into it asap. |
I did some digging and I think I know what the problem is. I do have a solution but I need to test it further. The issue seems to be in the nest/packages/core/router/router-explorer.ts Line 428 in 308599f
If the const contextId = createContextId();
const resolverObjectOrFunction = this.strategy.attach(contextId, request);
if (this.isContextIdResolverWithPayload(resolverObjectOrFunction)) {
contextId.getParent = resolverObjectOrFunction.resolve;
contextId.payload = resolverObjectOrFunction.payload;
} else {
contextId.getParent = resolverObjectOrFunction; //Here the payload is not set
}
return contextId; But then in the The fix I tried was to set the payload in the const contextId = createContextId();
const resolverObjectOrFunction = this.strategy.attach(contextId, request);
if (this.isContextIdResolverWithPayload(resolverObjectOrFunction)) {
contextId.getParent = resolverObjectOrFunction.resolve;
contextId.payload = resolverObjectOrFunction.payload;
} else {
contextId.getParent = resolverObjectOrFunction;
contextId.payload = request //<-- HERE
}
return contextId; But I need to run all the tests to make sure this will not break other things. Plus the same logic as per |
@vizio360 yeah that's was my first solution but see: #10793 (comment) |
@micalevisk PR is ok, it does solve the issue. |
637ceed
to
f396dc1
Compare
lgtm |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
regression introduce at v9.1.1
What is the current behavior?
When injecting
REQUEST
for non-durable providers, its value is always being context payload even when the injectable chain is not durable, like this:What is the new behavior?
non-durable providers can inject the
REQUEST
(orCONTEXT
. I didn't tested this patch withCONTEXT
tho) regardless of theContextIdStrategy#attach
. I'm under the assumption that the context id being resolved doesn't affect theREQUEST
provider for a non-durable provider.You can try this patch:
Does this PR introduce a breaking change?
Other information
After digging a bit into the source, I didn't find any other way to fix that bug other than checking if the tree is durable in order to define what would be the value for
REQUEST
/CONTEXT
provider.