typeorm: Could not find any entity of type when using specific commands.

Issue Description

Queries work when I use either QueryBuilder or Raw SQL, using find, findOne, getOne etc returns nothing.

Expected Behavior

The any query created with the following would return the expected user:

await db.getRepository<User>('User').findOneOrFail({ emailAddress });

// return
User {
firstName 'Foo',
lastName: 'Bar',
emailAddress: 'foo@bar.com'
}

Actual Behavior

await db.getRepository<User>('User').findOneOrFail({ emailAddress });
// "Could not find any entity of type \"User\" matching: {\n    \"emailAddress\": \"foo@bar.com\"\n}"

await db.getRepository<User>('User').createQueryBuilder()
    .where('emailAddress = :emailAddress', { emailAddress: `${emailAddress}` })
    .getOne();
// returns undefined

await db.getRepository<User>('User').createQueryBuilder()
    .where('emailAddress = :emailAddress', { emailAddress: `${emailAddress}` })
    .execute();
// works

Steps to Reproduce

Code was working fine locally and deployed, before completing a new deployment. Upon completing a new deployment (none of the above code was changed), the error began appearing. The error transferred to my local environment when I performed a fresh node_modules install (It was not happening until that happened, regardless of the status of the deployed version).

  1. Calling any find/findOne/getOne/findOneOrFail command reproduces the issue
@Entity('user')
export class User {
  @PrimaryGeneratedColumn()
  userId: number;

  @Column({ type: 'varchar', unique: true, length: 255 })
  emailAddress: string;

  @Column({ type: 'varchar', default: '' })
  phoneNumber: string;

  @Column({ type: 'varchar', default: '' })
  title: string;

  @Column('text')
  preferredName: string;

  @Column('text')
  firstName: string;

  @Column('text')
  lastName: string;

  @Column({ type: 'varchar', default: '' })
  profilePhotoURL: string;

  @Column('text')
  accountType: string;
}

export const getUserQuery = async (emailAddress: string) => {
  const db = await initDb(`${process.env.NODE_ENV}-db`); // Even hard-coding the selected DB makes no impact, have checked that.
  return db.getRepository(User).findOneOrFail({ emailAddress });

My Environment

Dependency Version
Operating System Ubuntu 20.04
Node.js version v12.16.3
Typescript version 3.9.10
TypeORM version 0.2.36

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api yes
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✅ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 23 (1 by maintainers)

Most upvoted comments

I’m using Postgres and I’m having the same problem.