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

Using CacheInterceptor on endpoint and returning classes using class-validator decorators and applying @Excluded() decorator is not excluding the attribute in the cached response. #148

Closed
2 of 4 tasks
zenstok opened this issue Aug 21, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@zenstok
Copy link

zenstok commented Aug 21, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When applying the CacheInterceptor on endpoints and returning classes that use class-validator decorators, the application of the @Excluded() decorator doesn't seem to exclude the attribute in the cached response. In the non-cached response it works as expected.

POST-CREATION: This applies only if you are using a redis store. I'm using cache-manager-redis-yet with version 4.1.1. Maybe i should redirect this issue on their repo.

Minimum reproduction code

https://github.com/nestjs/cache-manager

Steps to reproduce

  1. Apply cache interceptor on a route that returns an object which is an instance of a class with an @Excluded() decorator applied on an attribute.
  @UseInterceptors(CacheInterceptor)
  @CacheTTL(30000)
  @Get('/test')
  test() {
    return this.testService.getResult();
  }
  1. Check the initial response which should NOT return the excluded attribute, as expected. (non-cached response)

  2. Check the second response which should NOT return the excluded attribute, but surprisingly, the cache is not taking this into account and it also returns the excluded attribute. (cached response)

Expected behavior

The attribute exclusion should also apply to the cached response.

Package version

1.0.0

NestJS version

9.4.0

Node.js version

18.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@zenstok zenstok added the bug Something isn't working label Aug 21, 2023
@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants