Skip to content

Issue with OnUpdate on QueryBuilder #11549

Open
@dylan402

Description

@dylan402

Issue description

Error when using QueryBuilder and onUpdate with postgres driver

Expected Behavior

INSERT INTO "public"."category"("id", "name")
VALUES ($1, $2), ($3, $4)
ON CONFLICT ( "id" ) DO UPDATE SET "name" = EXCLUDED."name"

Actual Behavior

TypeORMError: Cannot get entity metadata for the given alias "public.category"

Steps to reproduce

await dataSource.manager
	.createQueryBuilder()
	.insert()
	.into('public.category', ['id', 'name'])
	.values([
	  { id: 1, name: 'Category 1' },
	  { id: 2, name: 'Category 2' },
	])
	.orUpdate(['name'], ['id'])
	.execute();

My Environment

Dependency Version
Operating System Windows 11 Pro 24H2
Node.js version 20.18.1
Typescript version 5.8.3
TypeORM version 0.3.25

Additional Context

When using the QueryBuilder without an entity, an error occurs due to PR #10458.

Currently, the issue happens on line 579, where it tries to access metadata that doesn’t exist.

Adding a check to validate the existence of the metadata on line 577 prevents the error

if (this.expressionMap.mainAlias!.hasMetadata)

But I’m not sure if that’s the correct solution.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

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

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

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