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

Validation is not performed on config loaded with custom loader #1497

Open
2 of 4 tasks
sergey-shablenko opened this issue Oct 16, 2023 · 2 comments
Open
2 of 4 tasks
Labels
bug Something isn't working

Comments

@sergey-shablenko
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

we load and validate config outside of nestjs and just provide already parsed config to the module like this

    ConfigModule.forRoot({
      isGlobal: true,
      ignoreEnvFile: true,
      ignoreEnvVars: true,
      expandVariables: false,
      // no validation needed, it is validated during load
      validate: (config) => config,
      load: [get],
    })

when we try to use config service

configService: ConfigService<EnvironmentVariables, true>

typings are correct, it recognises numbers, booleans, e.t.c, but returns raw string value from _cache causing broken types

Minimum reproduction code

aint nobody got time for that (sorry)

Steps to reproduce

No response

Expected behavior

validate logic should be called on objects loaded from custom loaders to have consistent logic and safe types

Package version

3.1.1

NestJS version

10.2.6

Node.js version

18.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Sorry that I did not provide reproduction code, but it is easy to track down without it. Either trust loaded config and add it to validated cache, or run validation logic to add it there
image

@sergey-shablenko sergey-shablenko added the bug Something isn't working label Oct 16, 2023
@sergey-shablenko
Copy link
Author

or maybe change order of operations, to fallback to internal config before process.env
image

@robbyyt
Copy link

robbyyt commented Jan 4, 2024

I bumped into this as well and would benefit from the behaviour being changed :D

EDIT: As a workaround, I just manually validated each slice before returning it from registerAs and ended up not having it on the main configuration object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants