Skip to content
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): Making Request scope non durable win over scope durable #10698

Merged
merged 2 commits into from Feb 1, 2023

Conversation

vizio360
Copy link
Contributor

@vizio360 vizio360 commented Dec 12, 2022

If an instance has at least one dependency that is Request scope non durable, then the instance should be Request scope non durable itself.

Closes #10594

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

If an instance has at least one dependency that is Request scope non durable, then the instance should be Request scope non durable itself.

Closes nestjs#10594
@micalevisk
Copy link
Member

could you please open a PR at https://github.com/nestjs/docs.nestjs.com to clarify this new behavior?

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Dec 14, 2022

@micalevisk PR to the docs doesn't seem to be needed (it should work as intended upon merging this PR)

@vizio360
Copy link
Contributor Author

vizio360 commented Dec 14, 2022

@kamilmysliwiec @micalevisk I do wonder if I also need to check the Dynamic Modules that use a factory. With my tests it seems that if at least one injected dependency to the factory method is durable then that factory method becomes durable even though it has some other dependencies that are Request non durable.

@vizio360
Copy link
Contributor Author

@kamilmysliwiec @micalevisk I do wonder if I also need to check the Dynamic Modules that use a factory. With my tests it seems that if at least one injected dependency to the factory method is durable then that factory method becomes durable even though it has some other dependencies that are Request non durable.

Actually I need to dig a bit further because I see the problem while using @golevelup/nestjs-graphql-request

@vizio360
Copy link
Contributor Author

vizio360 commented Dec 14, 2022

@kamilmysliwiec @micalevisk I do wonder if I also need to check the Dynamic Modules that use a factory. With my tests it seems that if at least one injected dependency to the factory method is durable then that factory method becomes durable even though it has some other dependencies that are Request non durable.

Actually I need to dig a bit further because I see the problem while using @golevelup/nestjs-graphql-request

Ok I think I spotted the issue in my tests. The .overrideProvider().useValue() sequence seems to set the Scope for the provider you pass as DEFAULT but keeps the durable flag as set in the original provider class.

My class definition

@Injectable({ scope: Scope.REQUEST, durable: false })
export class M2MTenantAuthService {

in my test

.overrideProvider(M2MTenantAuthService).useValue(m2mTokenMock)

and this is the debug data I got for that class

image

Notice the durable: false (as specified in the class definition) but the scope: 0

Wondering if because I use useValue it automatically assumes it is scope DEFAULT.

Anyway nothing to add to this PR.

@micalevisk
Copy link
Member

yeah, looks like there's no way to define the scope of overwrited providers when using .useValue. I can't tell if this is a limitation or not

private createOverrideByBuilder(
add: (provider: any) => TestingModuleBuilder,
): OverrideBy {
return {
useValue: value => add({ useValue: value }),

@vizio360
Copy link
Contributor Author

yeah, looks like there's no way to define the scope of overwrited providers when using .useValue. I can't tell if this is a limitation or not

private createOverrideByBuilder(
add: (provider: any) => TestingModuleBuilder,
): OverrideBy {
return {
useValue: value => add({ useValue: value }),

In theory it should maintain the scope defined in the original provider.

@vizio360
Copy link
Contributor Author

@kamilmysliwiec any idea when this can be merged and released?

@vizio360
Copy link
Contributor Author

@micalevisk @kamilmysliwiec @Papooch just a little nudge to know when we can expect this to be merged.

@micalevisk
Copy link
Member

micalevisk commented Jan 10, 2023

@vizio360 can you patch this to see if it will fix the issue described at #10809 as well? If yes, I'll close that PR

@vizio360
Copy link
Contributor Author

@vizio360 can you patch this to see if it will fix the issue described at #10809 as well? If yes, I'll close that PR

I can have a look, but is that PR not ready to be merged? Is it just a matter of including those changes in this one or to actually fix the problem that PR was created for?

@micalevisk
Copy link
Member

micalevisk commented Jan 10, 2023

it is but I didn't notice before that maybe yours would fix that issue as well but in a more cleaner way.

To clarify: I'm not asking you to bring those changes to here, but to check out if the bug described in there will be fixed by this PR.

@vizio360
Copy link
Contributor Author

it is but I didn't notice before that maybe yours would fix that issue as well but in a more cleaner way.

To clarify: I'm not asking you to bring those changes to here, but to check out if the bug described in there will be fixed by this PR.

sure, I'll have a look.

@vizio360 vizio360 marked this pull request as draft January 12, 2023 13:22
@vizio360
Copy link
Contributor Author

Just found that the enhancers tests are failing. Investigating...

@vizio360 vizio360 marked this pull request as ready for review January 12, 2023 15:28
@vizio360
Copy link
Contributor Author

@vizio360 can you patch this to see if it will fix the issue described at #10809 as well? If yes, I'll close that PR

Forgot to update on this, I checked and this PR does not solve the issue that #10809 is addressing.
#10809 fix seems ok to me.

@kamilmysliwiec
Copy link
Member

lgtm

@micalevisk
Copy link
Member

micalevisk commented Feb 2, 2023

seems like this has introduced a regression: #11002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Durable provider scope wins over non durable.
4 participants