Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeorm - InsertQueryBuilderCls is not a constructor

I use an entity manager for a transaction making sure there are no nested commits in the procedure that I call like this, I set the search_path since my proc calls unprefixed entities internally

async savetournamentTransaction(tournament: any, matchId: string) {
    await this.connection.manager.transaction(async (tournamentEntityManager) => {
      const tournamentRepository = tournamentEntityManager.getRepository(tournament);
      await tournamentRepository.query(`SET LOCAL search_path to ${matchId}`);
      await tournamentRepository.save(tournament);
      await tournamentRepository.query(
        `CALL fillOrganizationScheduleTable($1,${tournament.tournament_id});`,
        [matchId],
      );
    });
  }
}

However, typeorm gives me this error that I can't really comprehend:

[Nest] 790  - 09/16/2022, 4:40:43 PM   ERROR [ExceptionsHandler] InsertQueryBuilderCls is not a constructor
TypeError: InsertQueryBuilderCls is not a constructor
    at SelectQueryBuilder.insert (/mypath/desktop/prj/volleyball-organization/src/query-builder/QueryBuilder.ts:200:16)
    at SubjectExecutor.executeInsertOperations (/mypath/desktop/prj/volleyball-organization/src/persistence/SubjectExecutor.ts:430:26)
    at SubjectExecutor.execute (/mypath/desktop/prj/volleyball-organization/src/persistence/SubjectExecutor.ts:137:20)
    at EntityPersistExecutor.execute (/mypath/desktop/prj/volleyball-organization/src/persistence/EntityPersistExecutor.ts:194:36)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at /mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:155:13
    at EntityManager.transaction (/mypath/desktop/prj/volleyball-organization/src/entity-manager/EntityManager.ts:151:28)
    at tournamentsService.savetournamentTransaction (/mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:152:9)
    at tournamentsService.createtournament (/mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:113:9)
    at /mypath/desktop/prj/volleyball-organization/node_modules/@nestjs/core/router/router-execution-context.js:46:28  
  

I can't really find anything similar to this error, what might be the issue be, and how may I resolve it?

like image 527
mleko Avatar asked Aug 11 '26 08:08

mleko


1 Answers

I witnessed this error while I was debugging some DB tests in a Jest suite. The root of the issue is that the test was timing out while I was stepping through code.

Jest intercepts requires and imports, so after the test runner was in a timed-out state, an intercepted require() (deep in the TypeORM query runner code) was no-oping. This meant the InsertQueryBuilderCls was undefined.

like image 120
David Nutting Avatar answered Aug 14 '26 10:08

David Nutting



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!