Skip to content

fix(postgres): execute remaining relation-load and persistence paths sequentially to avoid pg 8.19.0 deprecation - #12421

Merged
Cprakhar merged 6 commits into
typeorm:masterfrom
kyungseopk1m:fix/postgres-deprecation-relation-load
May 5, 2026
Merged

Cprakhar merged 6 commits into
typeorm:masterfrom
kyungseopk1m:fix/postgres-deprecation-relation-load

Conversation

@kyungseopk1m

@kyungseopk1m kyungseopk1m commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the remaining half of #12238 (pg 8.19.0 deprecation warning), following the same direction as #12105 but in driver-agnostic code paths.

#12105 serialized the PostgresQueryRunner / CockroachQueryRunner metadata paths (loadTables, clearDatabase, dropEnumTypes). This PR addresses the relation-loading and persistence code paths that @pkuczynski pointed out in #12238 (comment) and that @max-brigade documented in their attached patch on the same issue.

Changed paths

  • EntityPersistExecutor — chunk-level SubjectExecutor build sequentially (otherwise concurrent SubjectDatabaseEntityLoader.load() invocations across chunks share the same client)
  • SubjectDatabaseEntityLoader.load() — group entity targets sequentially
  • SubjectExecutor.executeUpdateOperations() — update remaining subjects sequentially
  • SubjectExecutor.executeSoftRemoveOperations() — soft-delete subjects sequentially
  • SubjectExecutor.executeRecoverOperations() — restore subjects sequentially
  • SelectQueryBuilder — relationLoadStrategy: 'query' relation loading sequentially
  • RelationIdLoader.load() — relationIdAttributes loading sequentially

Each site is gated on postgres and cockroachdb, so non-postgres drivers keep the existing Promise.all behavior with no performance regression. Each branch carries the same comment: // Avoid concurrent queries on the same pg client; see #12238.

Out of scope

  • SubjectExecutor.broadcastBeforeEventsForAll / broadcastAfterEventsForAll use Promise.all(broadcasterResult.promises) to await user-defined listener/subscriber promises. Those are not typeorm-issued client.query() calls on the shared pg client, so they remain Promise.all.

Tests

Added regression test under test/github-issues/12238/:

  • "should keep relationLoadStrategy: 'query' working with ManyToMany on every supported driver except spanner" — runs against every configured driver to assert behavioral equivalence between the parallel and the sequential branches.

  • "should not emit pg 'client.query already executing' warning during relationLoadStrategy: 'query' on postgres and cockroachdb". Captures process.on('warning', ...) and exercises:

    • bulk manager.save(posts)
    • manager.save(posts, { chunk: 1 }) to drive the EntityPersistExecutor chunk path
    • manager.find(Post, { relations: { tags: true }, relationLoadStrategy: "query" })
    • re-save, softRemove, recover

    Asserts the "Calling client.query() when the client is already executing" warning does not fire on any of them.

Closes #12238

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Grey Divider


Action required

1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.
## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.
## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Inconsistent driver type source 🐞 Bug ⚙ Maintainability
Description
The new serialization gates in SubjectExecutor check driver type using different sources
(queryRunner.dataSource.driver.options.type vs queryRunner.dataSource.options.type), which
increases the risk of diverging behavior across persistence operations if either field’s semantics
change. Standardizing on one source (and ideally a shared helper) reduces the chance of accidentally
reintroducing concurrent pg queries in one path while others remain serialized.
Code

src/persistence/SubjectExecutor.ts[R826-834]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        // CockroachDB uses the pg package over a single connection too.
+        const driverType = this.queryRunner.dataSource.options.type
+        if (driverType === "postgres" || driverType === "cockroachdb") {
+            for (const subject of this.softRemoveSubjects) {
+                await softRemoveSubject(subject)
+            }
+        } else {
+            await Promise.all(this.softRemoveSubjects.map(softRemoveSubject))
Evidence
executeUpdateOperations gates serialization using
this.queryRunner.dataSource.driver.options.type, while executeSoftRemoveOperations and
executeRecoverOperations gate using this.queryRunner.dataSource.options.type; the inconsistency
is visible in the new code blocks added for #12238.

src/persistence/SubjectExecutor.ts[640-653]
src/persistence/SubjectExecutor.ts[826-835]
src/persistence/SubjectExecutor.ts[937-946]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New pg/cockroach serialization gates read the driver type from different properties (`queryRunner.dataSource.driver.options.type` vs `queryRunner.dataSource.options.type`). This inconsistency increases the maintenance burden and the likelihood of future regressions where one path is no longer correctly gated.
### Issue Context
These gates are intended to be consistent and easy to update (e.g., if the set of pg-like single-client drivers expands or if driver option shapes change).
### Fix Focus Areas
- Standardize driver-type reads to a single source across SubjectExecutor (pick either `this.queryRunner.dataSource.options.type` everywhere, or `this.queryRunner.dataSource.driver.options.type` everywhere).
- (Optional) Extract a small shared predicate (e.g., `isSingleClientPgLike(dataSourceOrQueryRunner)`) to avoid repeating the string comparisons.
### Fix Focus Areas (code locations)
- src/persistence/SubjectExecutor.ts[640-653]
- src/persistence/SubjectExecutor.ts[826-835]
- src/persistence/SubjectExecutor.ts[937-946]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.
### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.
### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]
### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

4. Duplicated pg driver checks 🐞 Bug ⚙ Maintainability ⭐ New
Description
The same postgres/cockroachdb driver-type branching is duplicated across multiple modules,
increasing the chance a future concurrency-related change is applied in one call site but missed in
others. This is not a functional bug today, but it makes the fix harder to maintain and audit over
time.
Code

src/persistence/EntityPersistExecutor.ts[R147-160]

+            // Avoid concurrent queries on the same pg client; see #12238.
+            // CockroachDB uses the pg package over a single connection too.
+            const driverType = this.dataSource.options.type
+            let executors: SubjectExecutor[]
+            if (driverType === "postgres" || driverType === "cockroachdb") {
+                executors = []
+                for (const entities of entitiesInChunks) {
+                    executors.push(await buildExecutor(entities))
+                }
+            } else {
+                executors = await Promise.all(
+                    entitiesInChunks.map(buildExecutor),
+                )
+            }
Evidence
Identical driverType === "postgres" || driverType === "cockroachdb" gating logic is repeated
across persistence and query-builder code paths, so any future adjustment (e.g., widening/narrowing
the set of serialized drivers or changing the rationale) requires coordinated edits in several
places.

src/persistence/EntityPersistExecutor.ts[146-160]
src/persistence/SubjectDatabaseEntityLoader.ts[148-159]
src/persistence/SubjectExecutor.ts[640-653]
src/query-builder/SelectQueryBuilder.ts[3718-3727]
src/query-builder/relation-id/RelationIdLoader.ts[397-409]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Multiple files duplicate the same driver-type check:

```ts
const driverType = ...options.type
if (driverType === "postgres" || driverType === "cockroachdb") {
 // sequential
} else {
 // Promise.all
}
```

This is currently consistent, but it creates maintenance risk (future changes can easily miss one of the call sites).

### Issue Context
These branches all implement the same policy: serialize TypeORM-issued queries on drivers that use a single `pg` client connection.

### Fix Focus Areas
Introduce a small shared helper/predicate (local util function or shared utility) and reuse it at these call sites.

- src/persistence/EntityPersistExecutor.ts[146-160]
- src/persistence/SubjectDatabaseEntityLoader.ts[148-159]
- src/persistence/SubjectExecutor.ts[640-653]
- src/persistence/SubjectExecutor.ts[826-835]
- src/persistence/SubjectExecutor.ts[937-946]
- src/query-builder/SelectQueryBuilder.ts[3718-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[397-409]

Example direction:
- Add `isPostgresFamilySingleClient(type: string): boolean` in a shared internal module (or a `DriverUtils` helper), then replace repeated inline checks with it.
- Keep behavior identical (postgres/cockroachdb only) unless you intentionally want to broaden the set.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Previous review results

Review updated until commit 5459622

Results up to commit 2779a9d


🐞 Bugs (2) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Action required
1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.
## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.
## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Inconsistent driver type source 🐞 Bug ⚙ Maintainability ⭐ New
Description
The new serialization gates in SubjectExecutor check driver type using different sources
(queryRunner.dataSource.driver.options.type vs queryRunner.dataSource.options.type), which
increases the risk of diverging behavior across persistence operations if either field’s semantics
change. Standardizing on one source (and ideally a shared helper) reduces the chance of accidentally
reintroducing concurrent pg queries in one path while others remain serialized.
Code

src/persistence/SubjectExecutor.ts[R826-834]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        // CockroachDB uses the pg package over a single connection too.
+        const driverType = this.queryRunner.dataSource.options.type
+        if (driverType === "postgres" || driverType === "cockroachdb") {
+            for (const subject of this.softRemoveSubjects) {
+                await softRemoveSubject(subject)
+            }
+        } else {
+            await Promise.all(this.softRemoveSubjects.map(softRemoveSubject))
Evidence
executeUpdateOperations gates serialization using
this.queryRunner.dataSource.driver.options.type, while executeSoftRemoveOperations and
executeRecoverOperations gate using this.queryRunner.dataSource.options.type; the inconsistency
is visible in the new code blocks added for #12238.

src/persistence/SubjectExecutor.ts[640-653]
src/persistence/SubjectExecutor.ts[826-835]
src/persistence/SubjectExecutor.ts[937-946]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
New pg/cockroach serialization gates read the driver type from different properties (`queryRunner.dataSource.driver.options.type` vs `queryRunner.dataSource.options.type`). This inconsistency increases the maintenance burden and the likelihood of future regressions where one path is no longer correctly gated.

### Issue Context
These gates are intended to be consistent and easy to update (e.g., if the set of pg-like single-client drivers expands or if driver option shapes change).

### Fix Focus Areas
- Standardize driver-type reads to a single source across SubjectExecutor (pick either `this.queryRunner.dataSource.options.type` everywhere, or `this.queryRunner.dataSource.driver.options.type` everywhere).
- (Optional) Extract a small shared predicate (e.g., `isSingleClientPgLike(dataSourceOrQueryRunner)`) to avoid repeating the string comparisons.

### Fix Focus Areas (code locations)
- src/persistence/SubjectExecutor.ts[640-653]
- src/persistence/SubjectExecutor.ts[826-835]
- src/persistence/SubjectExecutor.ts[937-946]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.
### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.
### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]
### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit c542f5d


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Action required
1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.
## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.
## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.
### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.
### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]
### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit da59108


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Action required
1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.
## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.
## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.
### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.
### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]
### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit f8428a6


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Action required
1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.
## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.
## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.
### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.
### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]
### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit fd11185


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Action required
1. New test under github-issues 📘 Rule violation ⚙ Maintainability
Description
This PR adds a regression test only under test/github-issues/12238 without placing the fix
coverage in test/functional. This violates the guideline to prefer functional tests for issue
fixes unless there is a clearly documented reason to stay in per-issue tests.
Code

test/github-issues/12238/issue-12238.test.ts[R12-13]

+describe("github issues > #12238 pg deprecation: relation-load and persistence paths", () => {
+    let dataSources: DataSource[]
Evidence
PR Compliance ID 3 requires issue fix coverage to go into test/functional (or have a clear reason
otherwise). The added test file is located under test/github-issues/12238 and is explicitly an
issue-scoped test (describe("github issues > #12238 ...")).

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12238/issue-12238.test.ts[12-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new regression test was added under `test/github-issues/12238`, but compliance requires issue-fix coverage to live in the functional test suite unless there is a clearly documented reason.

## Issue Context
Per PR Compliance ID 3, issue fixes should be validated in `test/functional` to avoid accumulating one-off issue folders.

## Fix Focus Areas
- test/github-issues/12238/issue-12238.test.ts[1-104]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. CockroachDB not serialized 🐞 Bug ☼ Reliability
Description
The new serialization logic is gated on options.type === "postgres", but the CockroachDB driver
also uses the pg package and its QueryRunner executes queries on a single connection via
databaseConnection.query(). This leaves CockroachDB on the concurrent Promise.all paths in these
shared persistence/relation-loading routines, so it can still trigger the same concurrent
client.query() deprecation warning behavior.
Code

src/persistence/SubjectDatabaseEntityLoader.ts[R148-155]

+        // Avoid concurrent queries on the same pg client; see #12238.
+        if (this.queryRunner.dataSource.driver.options.type === "postgres") {
+            for (const subjectGroup of subjectGroups) {
+                await loadSubjectGroup(subjectGroup)
+            }
+        } else {
+            await Promise.all(subjectGroups.map(loadSubjectGroup))
+        }
Evidence
Multiple modified sites only serialize when the driver type is exactly "postgres". CockroachDB is
implemented on top of the pg driver and its QueryRunner issues queries via
databaseConnection.query(...) on a single connection, i.e., the same kind of client concurrency
constraint this PR is mitigating. The added regression test also explicitly scopes the warning
assertion to postgres only, so it won’t catch CockroachDB warnings.

src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
src/persistence/EntityPersistExecutor.ts[149-161]
src/driver/cockroachdb/CockroachDriver.ts[1121-1129]
src/driver/cockroachdb/CockroachQueryRunner.ts[32-35]
src/driver/cockroachdb/CockroachQueryRunner.ts[280-306]
src/driver/DriverUtils.ts[41-45]
test/github-issues/12238/issue-12238.test.ts[52-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The serialization introduced to avoid concurrent `client.query()` calls is only enabled for `type === "postgres"`. CockroachDB also uses the `pg` client and runs queries via `databaseConnection.query()` on a single connection, so leaving it on the `Promise.all` branches can still produce the same deprecation warning.

### Issue Context
There is already a shared helper `DriverUtils.isPostgresFamily(driver)` that includes `cockroachdb`.

### Fix Focus Areas
- src/persistence/EntityPersistExecutor.ts[149-161]
- src/persistence/SubjectDatabaseEntityLoader.ts[146-155]
- src/persistence/SubjectExecutor.ts[663-674]
- src/persistence/SubjectExecutor.ts[863-870]
- src/persistence/SubjectExecutor.ts[988-995]
- src/query-builder/SelectQueryBuilder.ts[3720-3727]
- src/query-builder/relation-id/RelationIdLoader.ts[394-404]

### Suggested change
Expand the postgres-only condition to also cover CockroachDB (e.g., `type === "postgres" || type === "cockroachdb"`), or use a central helper (carefully, since `isPostgresFamily` also includes `aurora-postgres`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@kyungseopk1m
kyungseopk1m force-pushed the fix/postgres-deprecation-relation-load branch from fd11185 to f8428a6 Compare April 29, 2026 17:17
@pkg-pr-new

pkg-pr-new Bot commented May 3, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm@12421
    

commit: 5459622

kyungseopk1m and others added 2 commits May 4, 2026 12:53
…cockroachdb, spanner

- add @DeleteDateColumn to Tag entity; cascade softRemove on Post
  otherwise threw MissingDeleteDateColumnError on postgres and
  cockroachdb
- skip spanner in this suite: ManyToMany junction insert collides on
  the generated primary key, matching the precedent in
  test/functional/persistence/many-to-many/persistence-many-to-many.test.ts
@Cprakhar
Cprakhar requested review from G0maa, alumni and gioboa May 4, 2026 10:47

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kyungseopk1m

@Cprakhar Cprakhar changed the title fix(postgres): serialize remaining relation-load and persistence paths to avoid pg 8.19.0 deprecation fix(postgres): execute remaining relation-load and persistence paths sequentially to avoid pg 8.19.0 deprecation May 4, 2026
@Cprakhar
Cprakhar merged commit ed9bcb9 into typeorm:master May 5, 2026
47 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone May 5, 2026
@alumni

alumni commented May 10, 2026 •

Copy link
Copy Markdown
Collaborator

We need to discuss whether to revert this PR or fix the behavior to be consistent across all drivers.

Those issues that Qodo identified are really on-point.

QueryRunners are the ones responsible for interfacing with client, not SubjectDatabaseEntityLoader.ts‎ / EntityPersistExecutor.ts / SubjectExecutor.ts / RelationIdLoader.ts‎ / SelectQueryBuilder.ts. Those should be as driver-agnostic as they can possibly be.

While I don't usually like to see Promise.all because it causes non-deterministic behavior, it does help parallelize tasks - so this change might have an impact on performance, in an area that is prone to such issues.

In the QueryRunner we normally have a lock that prevents multiple queries to be executed simultaneously on the same DB connection. IMO, I would have looked for an issue there first.

@max-brigade

Copy link
Copy Markdown

My understanding is that Promise.all does not provide real query parallelism when all queries share the same physical transaction/connection. At best, the driver serializes them internally; at worst, the driver rejects or warns about concurrent usage. In pg specifically, that implicit internal queue existed historically, but it is now being deprecated because the driver does not want to support concurrent client.query() calls on an already-busy client. So for TypeORM paths that share one QueryRunner/client, sequential await seems like the correct behavior rather than a performance regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

DeprecationWarning: Calling client.query() when the client is already executing a query is deprecated and will be removed in [email protected]

5 participants