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

ValidationPipe sets "undefined" for Boolean parameter if not provided #12818

Closed
2 tasks done
myfunc opened this issue Nov 23, 2023 · 8 comments
Closed
2 tasks done

ValidationPipe sets "undefined" for Boolean parameter if not provided #12818

myfunc opened this issue Nov 23, 2023 · 8 comments
Labels
needs triage This issue has not been looked into type: bug 😭

Comments

@myfunc
Copy link

myfunc commented Nov 23, 2023

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

PR #10953

NestJS version

9.4.3 -> 10.2.10

Describe the regression

I encountered a breaking change while migrating to the new major version of Nest.js.

In version 9.4.3, the ParseBoolPipe from "@nestjs/common" used to set a parameter's value to "false" if it was not provided. Starting from version 10.0.0, the ValidationPipe::transformPrimitive() now sets a Boolean parameter to "undefined."

Unfortunately, this change is not mentioned in the Nest.js migration guide https://docs.nestjs.com/migration-guide and is not highlighted in the release notes.

Minimum reproduction code

No response

Input code

import {
  Controller,
  Get,
  ParseBoolPipe,
  Query,
} from '@nestjs/common';

@Controller('users')
export class LeaderboardUserController {

  @Get()
  async getAll(
    @Query('hideUsernames', ParseBoolPipe) hideUsernames: boolean,
  ) {
    return "data";
  }
}

Expected behavior

Endpoints returns "data".

Other

No response

@myfunc myfunc added needs triage This issue has not been looked into type: bug 😭 labels Nov 23, 2023
@micalevisk
Copy link
Member

micalevisk commented Nov 23, 2023

that's expected and it was a breaking change, as I described in that PR. That's why it was introduced in v10, not in v9

you should supply a default value, like with the others pipe

@micalevisk
Copy link
Member

btw that has nothing to do with ValidationPipe

it just for ParseBoolPipe

@myfunc
Copy link
Author

myfunc commented Nov 23, 2023

I wonder how many unexpected runtime issues like this I will face in v10.

@micalevisk
Copy link
Member

migration guide docs.nestjs.com/migration-guide and is not highlighted in the release notes.

image

feel free to add it in that page

@myfunc
Copy link
Author

myfunc commented Nov 23, 2023

Actually thank you, now I see the full list of such possible changes. Thank you for a quick response.

@micalevisk
Copy link
Member

micalevisk commented Nov 23, 2023

@myfunc

actually, in your case, you should see a validation error (400 bad request), not undefined, right? because ParseBoolPipe is expecting a boolean value

can you provide a minimum repro?

@myfunc
Copy link
Author

myfunc commented Nov 23, 2023

Yes, I see a validation error.
I think there is no need to make a minimal repo for that listed change. That's completely clear now.

@myfunc
Copy link
Author

myfunc commented Nov 23, 2023

That's risky breaking change, cause it reveals only in runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: bug 😭
Projects
None yet
Development

No branches or pull requests

2 participants