Repository navigation
fix(postgres): execute remaining relation-load and persistence paths sequentially to avoid pg 8.19.0 deprecation - #12421
Conversation
Code Review by Qodo
Context used 1. New test under github-issues
|
…s to avoid pg 8.19.0 deprecation
fd11185 to
f8428a6
Compare
commit: |
…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
|
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.
While I don't usually like to see In the |
|
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. |
…ially to avoid pg 8.19.0 deprecation (typeorm#12421) Co-authored-by: Prakhar Chhalotre <[email protected]>
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/CockroachQueryRunnermetadata 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-levelSubjectExecutorbuild sequentially (otherwise concurrentSubjectDatabaseEntityLoader.load()invocations across chunks share the same client)SubjectDatabaseEntityLoader.load()— group entity targets sequentiallySubjectExecutor.executeUpdateOperations()— update remaining subjects sequentiallySubjectExecutor.executeSoftRemoveOperations()— soft-delete subjects sequentiallySubjectExecutor.executeRecoverOperations()— restore subjects sequentiallySelectQueryBuilder—relationLoadStrategy: 'query'relation loading sequentiallyRelationIdLoader.load()—relationIdAttributesloading sequentiallyEach site is gated on
postgresandcockroachdb, so non-postgres drivers keep the existingPromise.allbehavior 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/broadcastAfterEventsForAllusePromise.all(broadcasterResult.promises)to await user-defined listener/subscriber promises. Those are not typeorm-issuedclient.query()calls on the shared pg client, so they remainPromise.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:manager.save(posts)manager.save(posts, { chunk: 1 })to drive theEntityPersistExecutorchunk pathmanager.find(Post, { relations: { tags: true }, relationLoadStrategy: "query" })save,softRemove,recoverAsserts the "Calling client.query() when the client is already executing" warning does not fire on any of them.
Closes #12238