Skip to content

Inconsistent handling of "undefined" between save() and update() #2331

@hallsbyra

Description

@hallsbyra

Issue type:

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

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native

TypeORM version:

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

If I update a nullable column with undefined, the value is changed to null.

This passes:

        // Given
        await testFixture.companyRepo.save(dummy.company({id: "C0", logo: Buffer.from("test", "base64")}))

        // When
        await testFixture.companyRepo.update("C0", {logo: undefined})

        // Then
        const c1 = await testFixture.companyRepo.findOneOrFail("C0")
        expect(c1.logo).to.be.null

If I instead save a nullable column with undefined, the value is not changed.

This also passes:

        // Given
        await testFixture.companyRepo.save(dummy.company({id: "C0", logo: Buffer.from("test", "base64")}))

        // When
        const c1 = await testFixture.companyRepo.findOneOrFail("C0")
        c1.logo = undefined
        await testFixture.companyRepo.save(c1)

        // Then
        const c2 = await testFixture.companyRepo.findOneOrFail("C0")
        expect(c2.logo).to.not.be.null

I think the behavior of save is more semantically correct.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions