[Bug]: Product module runs parallel queries inside a transaction (pg client.query() deprecation, fails with pg@9)
Package.json file
"@medusajs/medusa": "2.21.0",
"@medusajs/framework": "2.21.0",
"pg": "8.23.0"Node.js version
v22
Database and its version
PostgreSQL 16
Operating system name and version
Debian (node:22-slim container)
What happened?
Every run that creates product categories or product variants logs this warning:
DeprecationWarning: Calling client.query() when the client is already executing a query is deprecated and will be removed in [email protected]. Use async/await or an external async flow control mechanism instead.Traced with NODE_OPTIONS=--trace-deprecation, it comes from two places in @medusajs/product that run queries in parallel inside a transaction, so they all go to the same pg client:
1. ProductCategoryRepository.create (packages/modules/product/src/repositories/product-category.ts, around line 395): a Promise.all over the new categories, each one calling manager.count(...) for its siblings.
at SqlEntityManager.count (@mikro-orm/core/EntityManager.js:1282:23)
at @medusajs/product/src/repositories/product-category.ts:400:31
at async Promise.all (index 2)
at ProductCategoryRepository.create (@medusajs/product/src/repositories/product-category.ts:395:24)
at ProductCategoryService.create (@medusajs/product/src/services/product-category.ts:162:12)
at PostgreSqlConnection.transactional (@mikro-orm/knex/AbstractSqlConnection.js:58:25)
…
at createProductCategoriesStep (@medusajs/core-flows/src/product-category/steps/create-product-categories.ts:36:21)2. ProductModuleService.createVariants_ (packages/modules/product/src/services/product-module-service.ts, around line 629): a promiseAll([...]) of several list calls.
at AbstractService_.list (@medusajs/utils/src/modules-sdk/medusa-internal-service.ts:230:14)
at async Promise.allSettled (index 0)
at promiseAll (@medusajs/utils/src/common/promise-all.ts:27:18)
at ProductModuleService.createVariants_ (@medusajs/product/src/services/product-module-service.ts:629:7)
at PostgreSqlConnection.transactional (@mikro-orm/knex/AbstractSqlConnection.js:58:25)
…
at ProductModuleService.createProductVariants (@medusajs/product/src/services/product-module-service.ts:606:22)Both patterns are still the same on develop as of 2026-09-24.
Expected behavior
No overlapping queries on a transaction's client. Inside a transaction every query shares one connection, so running them with Promise.all gives no concurrency anyway (pg queues them); it only triggers the deprecation. With pg@9 this becomes an error, and creating categories or variants would fail.
A sequential for … of with await inside the transactional paths would keep the same behaviour without the warning.
Link to reproduction repo
No public repo. To reproduce with a stock Medusa 2.21 project:
- Run with
NODE_OPTIONS=--trace-deprecation. - Call
createProductCategoriesWorkflowwith two or more categories under the same parent, orcreateProductsWorkflowwith a product that has variants. - The warning appears with the stacks above.
Source: medusajs/medusa