Skip to content

.save() returns columns marked select: false #4591

Closed

Description

@0radek

Issue type:

[ ] question
[X] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[X] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[X] latest
[ ] @next
[ ] 0.x.x (or put your version here)

I have a deletedAt column on my entities which are select: false. This works just fine for any select queries.

However, when using .save(), the returned values includes properties which are not supposed to be selected.

Is this standard behavior, or should this be considered a bug?

Activity

  1. Redanski commented on Feb 11, 2020

    @Redanski
  2. carlosempd commented on Feb 20, 2020

    @carlosempd
  3. ardyfeb commented on Mar 30, 2020

    @ardyfeb
  4. kostia-official commented on May 8, 2020

    @kostia-official
  5. KevLehman commented on May 31, 2020

    @KevLehman

    Same here. What I'm doing is to use the rest operator to hide manually the properties. But this shouldn't be the way.

    const { password, ...user } = await repo.save(u);
    
  6. ablankenship10 commented on May 25, 2021

    @ablankenship10

    Any updates on this? The workaround above is somewhat tedious and causes typing issues when attempting to return an instance of your entity missing expected fields. I can take a crack at it but unsure on direction. Has it been decided this is infact a bug and save() functionality should be fixed, or should we add a key, say returning: bool to ColumnOptions and make it an option without changing current functionality?

  7. tkssharma commented on May 28, 2021

    @tkssharma
         const userSupplierData = this.userSupplierTagsRepo.create();
          userSupplierData.organization_id = organization_id;
          userSupplierData.user_id = user_id;
          userSupplierData.supplier_profile = supplier;
          return  await this.userSupplierTagsRepo.save({ ...userSupplierData, ...payload })
    

    How can I hide supplier_profile foreign key Table data coming in response after it saved
    marking selected false won't work when we are doing same

  8. Ojka91 commented on Aug 16, 2021

    @Ojka91

    Another workaround after the save() is to delete de property like this
    await Entity.save(); delete Entity.password; return Entity;

    Indeed tedious to do...

  9. laurent-brisbois commented on Nov 5, 2021

    @laurent-brisbois

    In my User entity I have :

      @Column({select: false})
      password: string;

    However when I'm doing :

      @Post()
      async create(@Body() body: UserCreateDto): Promise<User> {
        const hashedPassword = await bcrypt.hash(body.password, 10);
        return this.userService.create({
          firstName: body.firstName,
          lastName: body.lastName,
          email: body.email,
          password: hashedPassword,
        });
      }

    with my service being :

      async create(data): Promise<User> {
        return this.userRepository.save(data);
      }

    I get this answer, with the password :

    {
        "firstName": "John",
        "lastName": "Doe",
        "email": "[email protected]",
        "password": "the undesired password",
        "id": 13
    }

    Which shouldn't happen. Is something going to be done ? Or do we have to use the workarounds ? Because I see that this issue has been open since 2019.

    For info, I'm currently using these versions :

    "@nestjs/typeorm": "^8.0.2"
    "typeorm": "^0.2.38"

  10. abigmiu commented on Aug 17, 2022

    @abigmiu

    when use {select: false}.。

    // This column will not be selected by find functions and QueryBuilder
    @column({select: false})
    password: string

    if you used in save. i tried class-transformer

    @Exclude()
        @Column({
            default: false,
            select: false,
        })
        isDel: false;

    and add interceptor in controller

    @UseInterceptors(ClassSerializerInterceptor)
    export class CategoryController {}
    
  11. mahoo12138 commented on Oct 7, 2022

    @mahoo12138

    Also in the sqlite driver 😕

  12. bombillazo commented on Oct 22, 2022

    @bombillazo

    Updates on this issue? This poses a known security risk not even mentioned in the docs:
    image

  13. 11 remaining items

  14. github-actions commented on Sep 18, 2025

    @github-actions

    TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).

    As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.

    🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
    If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.

  15. qumberrizvi commented on Jan 25, 2026

    @qumberrizvi

    This issue is still relevant. Returning columns that were explicitly excluded from selection can be dangerous, especially for sensitive fields.

  16. reopened this on Jan 25, 2026
  17. gioboa commented on Jan 25, 2026

    @gioboa
    Collaborator

    Thanks @qumberrizvi for the heads up. I will take a look at it.

  18. alumni commented on Jun 3, 2026

    @alumni
    Collaborator

    The behavior described in the issue as a "bug" was the intended behavior, we will restore it in both 0.3 and 1.0.

    Even though the column has select: false, if we remove the property, we will cause data loss for the users. See #12473.

    So if you don't want to keep the property after saving, you'd need to delete it yourself, but select: false is NOT the way to do it.

    Another possible solution would be to implement a new feature for "ephemeral" or "hidden" properties - that disappear when saved.

    If deleting the property yourself after saving is too difficult, please open a feature request :)

  19. locked as resolved and limited conversation to collaborators on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions