Skip to content

Multi-tenant: tenant deletion fails with DrizzleQueryError — transaction aborted (Postgres) #14576

Open

Description

@TomSteer

Describe the Bug

Deleting a tenant in the multi-tenant plugin using the Postgres adapter fails. A Drizzle/Postgres error aborts the transaction.

{
  "type": "DrizzleQueryError",
  "message": "Failed query: delete from \"payload_preferences\" where \"payload_preferences\".\"key\" in ($1)\nparams: collection-tenants-3: current transaction is aborted, commands ignored until end of transaction block"
}

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/examples/multi-tenant

Reproduction Steps

  1. Clone the multi-tenant example.
  2. Configure the example to use Postgres (set DATABASE_URL to a Postgres DB) so @payloadcms/db-postgres is used.
  3. Start the project and log in to the admin.
  4. Create a tenant.
  5. Attempt to delete the tenant via the admin UI.
  6. Observe the delete fails and the transaction is aborted.

Which area(s) are affected? (Select all that apply)

plugin: multi-tenant, db: postgres

Environment Info

payload: 3.63.0
@payloadcms/plugin-multi-tenant: 3.63.0
@payloadcms/db-postgres: 3.63.0

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Nov 12, 2025
  2. removed
    validate-reproduction
    on Nov 12, 2025
  3. mikkelwf commented on Nov 13, 2025

    @mikkelwf
    Contributor

    Its not only a multi-tenant issue..

  4. christopherpickering commented on Dec 20, 2025

    @christopherpickering

    I'm getting the same error in a "magazines" collection. I try to delete an entry from the payloadui and get this log:

    [21:03:48] ERROR: Failed query: delete from "payload_preferences" where "payload_preferences"."key" in ($1)
    params: collection-magazines-931
    err: {
    "type": "d",
    "message": "Failed query: delete from \"payload_preferences\" where \"payload_preferences\".\"key\" in ($1)\nparams: collection-magazines-931: current transaction is aborted, commands ignored until end of transaction block",
    "stack":
    Error: Failed query: delete from "payload_preferences" where "payload_preferences"."key" in ($1)
    params: collection-magazines-931
    at p.queryWithCache (/app/node_modules/.pnpm/drizzle-orm%400.44.7_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_pg%408.16.3/node_modules/src/pg-core/session.ts:73:11)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at Object.t [as deleteWhere] (/app/node_modules/.pnpm/%40payloadcms%2Bdrizzle%403.68.0_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_payload%403.68.0_graphql%401_hivkjcirgcunb4ymm4nslyycxy/node_modules/%40payloadcms/drizzle/src/postgres/deleteWhere.ts:5:39)
    at Object.s [as deleteMany] (/app/node_modules/.pnpm/%40payloadcms%2Bdrizzle%403.68.0_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_payload%403.68.0_graphql%401_hivkjcirgcunb4ymm4nslyycxy/node_modules/%40payloadcms/drizzle/src/deleteMany.ts:59:3)
    at a_ (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/preferences/deleteUserPreferences.js:32:9)
    at aW (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/collections/operations/delete.js:214:9)
    at ty (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/collections/endpoints/delete.js:10:20)
    at g (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/utilities/handleEndpoints.js:191:26)
    at /app/node_modules/.pnpm/path-to-regexp%406.3.0/node_modules/path-to-regexp/src/index.ts:36:6
    at rU.do (/app/node_modules/.pnpm/next@16.1.0-canary.16_@babel+core@7.28.5_@opentelemetry+api@1.9.0_react-dom@19.2.1_react@19.2_zrylbxjvgq6pkukrnubleobvwe/node_modules/next/dist/compiled/next-server/webpack:/next/src/server/route-modules/app-route/module.ts:600:15)
    caused by: error: current transaction is aborted, commands ignored until end of transaction block
    at /app/node_modules/.pnpm/pg@8.16.3/node_modules/pg/lib/client.js:545:17
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at /app/node_modules/.pnpm/drizzle-orm%400.44.7_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_pg%408.16.3/node_modules/src/node-postgres/session.ts:149:14
    at p.queryWithCache (/app/node_modules/.pnpm/drizzle-orm%400.44.7_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_pg%408.16.3/node_modules/src/pg-core/session.ts:71:12)
    at Object.t [as deleteWhere] (/app/node_modules/.pnpm/%40payloadcms%2Bdrizzle%403.68.0_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_payload%403.68.0_graphql%401_hivkjcirgcunb4ymm4nslyycxy/node_modules/%40payloadcms/drizzle/src/postgres/deleteWhere.ts:5:39)
    at Object.s [as deleteMany] (/app/node_modules/.pnpm/%40payloadcms%2Bdrizzle%403.68.0_%40opentelemetry%2Bapi%401.9.0_%40types%2Bpg%408.10.2_payload%403.68.0_graphql%401_hivkjcirgcunb4ymm4nslyycxy/node_modules/%40payloadcms/drizzle/src/deleteMany.ts:59:3)
    at a_ (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/preferences/deleteUserPreferences.js:32:9)
    at aW (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/collections/operations/delete.js:214:9)
    at ty (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/collections/endpoints/delete.js:10:20)
    at g (/app/node_modules/.pnpm/payload%403.68.0_graphql%4016.12.0_typescript%405.9.3/node_modules/payload/dist/utilities/handleEndpoints.js:191:26)
    "query": "delete from \"payload_preferences\" where \"payload_preferences\".\"key\" in ($1)",
    "params": [
    "collection-magazines-931"
    ]
    }

    we are heavily using the api for other tasks (inserting/updating), do you think an error that was not rolled back in another update is causing this?

  5. max-degterev commented on Jan 13, 2026

    @max-degterev

    I have this since upgrading to 3.70 in a collection with blocks

  6. salaarkhan-dev commented on Jan 13, 2026

    @salaarkhan-dev

    Any solution facing this issue while deleting tenant?

  7. christopherpickering commented on Jan 14, 2026

    @christopherpickering

    ...My error was caused by fk's I forgot to delete 🤭

  8. mattbolt commented on Jan 15, 2026

    @mattbolt

    I have the same issue trying to delete a particular file in the media collection. I was able to delete others fine, but not this specific file. it doesn't seem to have anything extraordinarily different in the db compared to other files.

    Running Payload 3.70.0 in dev mode on localhost (app directory paths below adjusted to obfuscate personal info).

    [17:04:53] ERROR: Failed query: delete from "payload_preferences" where "payload_preferences"."key" in ($1)
    params: collection-media-1
        err: {
          "type": "DrizzleQueryError",
          "message": "Failed query: delete from \"payload_preferences\" where \"payload_preferences\".\"key\" in ($1)\nparams: collection-media-1: current transaction is aborted, commands ignored until end of transaction block",
          "stack":
              Error: Failed query: delete from "payload_preferences" where "payload_preferences"."key" in ($1)
              params: collection-media-1
                  at NodePgPreparedQuery.queryWithCache (file:///app/node_modules/.pnpm/drizzle-orm@0.44.7_@types+pg@8.10.2_pg@8.16.3/node_modules/drizzle-orm/pg-core/session.js:41:15)
                  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
                  at async Object.deleteWhere (file:///app/node_modules/.pnpm/@payloadcms+drizzle@3.70.0_@types+pg@8.10.2_payload@3.70.0_graphql@16.12.0_typescript@5.9.3__pg@8.16.3/node_modules/@payloadcms/drizzle/dist/postgres/deleteWhere.js:3:5)
                  at async Object.deleteMany (file:///app/node_modules/.pnpm/@payloadcms+drizzle@3.70.0_@types+pg@8.10.2_payload@3.70.0_graphql@16.12.0_typescript@5.9.3__pg@8.16.3/node_modules/@payloadcms/drizzle/dist/deleteMany.js:39:5)
                  at async deleteUserPreferences (file:///app/node_modules/.pnpm/payload@3.70.0_graphql@16.12.0_typescript@5.9.3/node_modules/payload/dist/preferences/deleteUserPreferences.js:32:9)
                  at async deleteOperation (file:///app/node_modules/.pnpm/payload@3.70.0_graphql@16.12.0_typescript@5.9.3/node_modules/payload/dist/collections/operations/delete.js:214:9)
                  at async deleteHandler (file:///app/node_modules/.pnpm/payload@3.70.0_graphql@16.12.0_typescript@5.9.3/node_modules/payload/dist/collections/endpoints/delete.js:10:20)
                  at async handleEndpoints (file:///app/node_modules/.pnpm/payload@3.70.0_graphql@16.12.0_typescript@5.9.3/node_modules/payload/dist/utilities/handleEndpoints.js:196:26)
                  at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+next@3.70.0_@types+react@19.2.8_graphql@16.12.0_monaco-editor@0.54.0_next@1_61c4383f3e2205334d475bd28c452ea7/node_modules/@payloadcms/next/dist/routes/rest/index.js:32:20)
                  at async AppRouteRouteModule.do (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:5:38696)
                  at async AppRouteRouteModule.handle (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:5:45978)
                  at async responseGenerator (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:206:38)
                  at async AppRouteRouteModule.handleResponse (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:1:187565)
                  at async handleResponse (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:268:32)
                  at async handler (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:320:13)
                  at async DevServer.renderToResponseWithComponentsImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1422:9)
                  at async DevServer.renderPageComponent (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1474:24)
                  at async DevServer.renderToResponseImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1514:32)
                  at async DevServer.pipeImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1025:25)
                  at async NextNodeServer.handleCatchallRenderRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/next-server.js:393:17)
                  at async DevServer.handleRequestImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:916:17)
                  at async /app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/dev/next-dev-server.js:399:20
                  at async Span.traceAsyncFn (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/trace/trace.js:157:20)
                  at async DevServer.handleRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/dev/next-dev-server.js:395:24)
                  at async invokeRender (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:240:21)
                  at async handleRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:437:24)
                  at async requestHandlerImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:485:13)
                  at async Server.requestListener (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/start-server.js:226:13)
              caused by: error: current transaction is aborted, commands ignored until end of transaction block
                  at /app/node_modules/.pnpm/pg@8.16.3/node_modules/pg/lib/client.js:545:17
                  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
                  at async file:///app/node_modules/.pnpm/drizzle-orm@0.44.7_@types+pg@8.10.2_pg@8.16.3/node_modules/drizzle-orm/node-postgres/session.js:113:20
                  at async NodePgPreparedQuery.queryWithCache (file:///app/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/pg-core/session.js:39:16)
                  at async Object.deleteWhere (file:///app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@payloadcms/drizzle/dist/postgres/deleteWhere.js:3:5)
                  at async Object.deleteMany (file:///app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@payloadcms/drizzle/dist/deleteMany.js:39:5)
                  at async deleteUserPreferences (file:///app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/preferences/deleteUserPreferences.js:32:9)
                  at async deleteOperation (file:///app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/operations/delete.js:214:9)
                  at async deleteHandler (file:///app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/endpoints/delete.js:10:20)
                  at async handleEndpoints (file:///app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/utilities/handleEndpoints.js:196:26)
                  at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_next@1_61c4383f3e2205334d475bd28c452ea7/node_modules/@payloadcms/next/dist/routes/rest/index.js:32:20)
                  at async AppRouteRouteModule.do (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:5:38696)
                  at async AppRouteRouteModule.handle (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:5:45978)
                  at async responseGenerator (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:206:38)
                  at async AppRouteRouteModule.handleResponse (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:1:187565)
                  at async handleResponse (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:268:32)
                  at async handler (webpack-internal:///(rsc)/./node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?name=app%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&page=%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute&appPaths=&pagePath=private-next-app-dir%2F(payload)%2Fapi%2F%5B...slug%5D%2Froute.ts&appDir=%2Fapp%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fapp&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D&isGlobalNotFoundEnabled=!:320:13)
                  at async DevServer.renderToResponseWithComponentsImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1422:9)
                  at async DevServer.renderPageComponent (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1474:24)
                  at async DevServer.renderToResponseImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1514:32)
                  at async DevServer.pipeImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:1025:25)
                  at async NextNodeServer.handleCatchallRenderRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/next-server.js:393:17)
                  at async DevServer.handleRequestImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/base-server.js:916:17)
                  at async /app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/dev/next-dev-server.js:399:20
                  at async Span.traceAsyncFn (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/trace/trace.js:157:20)
                  at async DevServer.handleRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/dev/next-dev-server.js:395:24)
                  at async invokeRender (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:240:21)
                  at async handleRequest (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:437:24)
                  at async requestHandlerImpl (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/router-server.js:485:13)
                  at async Server.requestListener (/app/node_modules/.pnpm/next@15.5.9_@playwright+test@1.56.1_react-dom@19.2.3_react@19.2.3__react@19.2.3_sass@1.77.4/node_modules/next/dist/server/lib/start-server.js:226:13)
          "query": "delete from \"payload_preferences\" where \"payload_preferences\".\"key\" in ($1)",
          "params": [
            "collection-media-1"
          ]
        }
     DELETE /api/media?limit=0&where%5Band%5D%5B0%5D%5Bid%5D%5Bin%5D%5B0%5D=1 500 in 44ms
  9. mattbolt commented on Jan 15, 2026

    @mattbolt

    I have the same issue trying to delete a particular file in the media collection. I was able to delete others fine, but not this specific file. it doesn't seem to have anything extraordinarily different in the db compared to other files.

    Running Payload 3.70.0 in dev mode on localhost (app directory paths below adjusted to obfuscate personal info).

    Ahh - so I worked it out. When trying to manually delete the entry from the media table I got a constraint error as the image in question was assigned to a relationship field of another post that was not allowed to be null.

    Not sure what could natively be built into the payload engine - but would be great to get a useful error along the lines of "Unable to delete this document as it is currently referenced by another document." and better still a reference to which related document is using it.

  10. AlessioGr commented on Feb 5, 2026

    @AlessioGr
    Member

    You can test if this canary fixes it: 3.75.0-internal.836af83. Will require a schema migration, don't recommend using in a production db as we don't yet know if we'll go ahead with this fix

    Nvm, probably need to fix this a different way

  11. TomSteer commented on Feb 24, 2026

    @TomSteer
    Author

    @AlessioGr Just following up after some additional testing.
    It looks like there are two separate problems, both seem related to the afterTenantDelete cleanup hook.

    1. Hang/deadlock when a tenant‑scoped collection exists

    When deleting a tenant that has a relationship field pointing to documents in a tenant‑scoped collection, the request hangs indefinitely with no errors logged.
    Setting cleanupAfterTenantDelete: false prevents the hang, which suggests the cleanup hook is competing with locks already held by the parent transaction and getting stuck.

    2. Constraint violation when users are assigned to the tenant

    Separately, if a user is associated with the tenant via the tenantsArrayField, the delete operation fails with the following constraint error:

    Failed query: delete from "tenants" where "tenants"."id" = $1
    params: 00000000-0000-0000-0000-000000000000: null value in column "tenant_id" of relation "admins_tenants" violates not-null constraint
    
  12. snakemastr commented on Jun 11, 2026

    @snakemastr

    Any updates on this issue? Cleanup after delete is a pretty usefull feature to me

  13. zakiahmedkgp commented on Oct 7, 2026

    @zakiahmedkgp

    If you have versions enabled on your Collections, then even after de-referencing the document you want to delete from all the other collections would still not remove the reference from older versions.

    For example, you have media and posts (with versions enabled) Collections and posts have media as required. Now if you want to delete a media document you will have to de-reference it from all posts documents and from any older versions of that posts document

  14. MRNAQA commented on Nov 18, 2026

    @MRNAQA

    reproduced on 3.94.0 with @payloadcms/plugin-multi-tenant and @payloadcms/db-postgres. there are two causes.

    the tenant column in the users tenants array is NOT NULL, because the plugin marks the field required. its foreign key is ON DELETE SET NULL. so deleting a tenant fails while a user still has it, before afterTenantDelete runs.

    tenant-scoped rows also use ON DELETE SET NULL. when the tenant row goes, their tenant id becomes null before the afterDelete cleanup runs. the cleanup's where tenant in [id] then finds nothing, and the rows stay with no tenant.

    running the cleanup in beforeDelete fixes both.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSengagement: mediumstatus: needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions