question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

findOneOrFail throws when selecting a null valued column

See original GitHub issue

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:

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

findOneOrFail() throws when it shoulddn’t.

Given this entity:

@Entity()
class Company {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    name: string

    @Column({nullable:true})
    nullName: string
}

then this snippet shows the problem:

// Given
const company = new Company()
company.name = "Company A"
await companyRepo.save(company)

// Then - This works
const c1 = await companyRepo.findOneOrFail(company.id, {select: ["name"]})
// Then - This throws "EntityNotFound: Could not find any entity of type "Company" matching: 1"
const c2 = await companyRepo.findOneOrFail(company.id, {select: ["nullName"]})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
wiktor-obrebskicommented, Jul 18, 2022

it’s very confusing and can easily lead to errors that can be missed before production release. if typeorm need id, it should always fetch id, even if it is not asked for it.

6reactions
akwodkiewiczcommented, Sep 17, 2021

What is the reason for ~the bug to occur~ this behaviour? Is the entity id column always required, or is selecting a single nullable column parsed in a wrong way, when the value is null?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel - find by custom column or fail - Stack Overflow
So call firstOrFail before where. Model::firstOrFail()->where('something', $value).
Read more >
typeorm/typeorm - Gitter
This is the errors typeorm throws from the console. query: 'ALTER TABLE "book_reading_status" ADD "readingStatus" integer NOT NULL', message: 'column ...
Read more >
typeorm: CHANGELOG
stringify() to json/jsonb column types in Postgres. Instead, we delegate value directly to underlying pg driver. This is a correct way of handling...
Read more >
Model Querying - Finders - Sequelize
Finder methods are the ones that generate SELECT queries. ... If the defaults do not contain values for every column, Sequelize will take ......
Read more >
partitioning on a null valued column - Forums - IBM Support
Is it possible to create partitions on field that has null values ? I would like to create the partition key for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found