Skip to content

fix: avoid postgres 100-argument limit in findRollbackById - #4924

Merged
Siumauricio merged 1 commit into
Dokploy:canaryfrom
dmtrTm:fix/rollback-query-arg-limit
Jul 28, 2026
Merged

fix: avoid postgres 100-argument limit in findRollbackById#4924
Siumauricio merged 1 commit into
Dokploy:canaryfrom
dmtrTm:fix/rollback-query-arg-limit

Conversation

@dmtrTm

@dmtrTm dmtrTm commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What is this PR about?

Rolling back any application on canary fails with an opaque HTTP 400 "Error input: Rolling back". The real error is only in the backend log, and it is the query itself, before any rollback logic runs:

Error: Failed query: select "rollbacks"."rollbackId", ... json_build_array("rollbacks_deployment_application"...
    at findRollbackById (packages/server/src/services/rollbacks.ts:106)
  [cause]: PostgresError: cannot pass more than 100 arguments to a function
    code: '54023'

findRollbackById() hydrated deployment -> application -> environment -> project, so drizzle compiled every column of application plus one blob per nested relation into a single json_build_array(...) call. Postgres caps that at the hard-compiled FUNC_MAX_ARGS = 100.

At 99 columns the call sat at exactly 99 + 1 = 100 - right on the limit. 0175_fantastic_peter_quill.sql added networkIds and detachDokployNetwork, taking application to 101 columns, so every rollback now fails.

None of that nested data is actually read: the rollback router only uses deployment.applicationId, and rollback() / removeRollbackById() read the rollback row itself (deploymentId, image, fullContext) and re-fetch the application through findApplicationById(). Dropping the nested relations is enough, and tsc --noEmit confirms nothing else consumed them.

This is the same failure and the same fix shape as #4256 / #4257, which narrowed findPreviewDeploymentById. After this change, findRollbackById is no longer the odd one out: findDeploymentById, centralizedDeploymentsWith and findPreviewDeploymentById all narrow their nested application selection already.

The pressure was flagged in advance in #4240:

the application table already has 99 columns on canary, and Postgres caps json_build_array() at 100 arguments ... any additional column from any PR will re-trip this

How this was verified

Local Dokploy dev instance (canary @d768adb6a, Postgres 16.14, single-node swarm), application with rollbacks enabled against a local registry, two deployments, then Rollback:

  • Before - HTTP 400, backend log shows PostgresError: cannot pass more than 100 arguments to a function (54023) raised from findRollbackById.
  • After - the query executes, the 54023 error is gone entirely, and the rollback proceeds all the way into rollbackApplication().

Scope check on the same instance: project.all, project.one, application.one, deployment.all, domain.byApplicationId, schedule.list, volumeBackups.list and previewDeployment.all all return 200 - they already narrow their nested application selection.

Three other by-id finders do carry the identical un-narrowed shape and fail the same way on canary today. Calling them directly against the database (bypassing the routers) gives:

finPortById:          PostgresError 54023 (cannot pass more than 100 arguments to a function)
findScheduleById:     PostgresError 54023
findVolumeBackupById: PostgresError 54023

They are invisible from the API because their routers wrap the cause in a generic message the same way the rollback router does - port.one reports "Port not found", schedule.one and volumeBackups.one likewise - so the real error never reaches the client or the log. Unlike the rollback path, those three do read the nested data, so the correct fix there is columns: narrowing (the #4257 form) rather than dropping the relation. I kept this PR to the rollback path so it stays reviewable and independently verifiable; happy to send a follow-up for the other three, or to fold them in here if you prefer a single change.

Related: with this PR applied, rollback then hits a second, independent bug - ${{environment.*}} variables are not resolved during rollback - which is fixed in #4923. The two are separate one-liners in the same file but different functions; they do not conflict.

Checklist

Before submitting this PR, please make sure that:

Issues related (if applicable)

Same class of bug as #4256 / #4257 (findPreviewDeploymentById).

Screenshots (if applicable)

N/A - Backend query change, verified end to end as described above.

Rolling back any application fails with

  PostgresError: cannot pass more than 100 arguments to a function (54023)

since 0175_fantastic_peter_quill took the application table to 101 columns.
findRollbackById hydrated deployment -> application -> environment -> project,
so drizzle compiled all 101 application columns plus the nested blob into one
json_build_array() call, above the FUNC_MAX_ARGS = 100 limit. At 99 columns it
sat exactly on the limit.

None of that nested data is read: the routers only use deployment.applicationId,
and rollback()/removeRollbackById() read the rollback row itself. Drop the nested
relations, the same shape as Dokploy#4257 for findPreviewDeploymentById.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dmtrTm
dmtrTm requested a review from Siumauricio as a code owner July 28, 2026 08:53
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jul 28, 2026
@Siumauricio
Siumauricio merged commit 069939e into Dokploy:canary Jul 28, 2026
4 checks passed
windinternet added a commit to windinternet/dokploy that referenced this pull request Jul 29, 2026
Brings in the upstream/canary HEAD (5df820a) as an ancestor of this
branch using -s ours, matching the 2026-07-15 sync policy. The merge
content is intentionally empty; this commit only records that every
cherry-picked upstream commit has been reviewed and either integrated
or explicitly rejected:

  - 32 security fixes (Dokploy#4855-Dokploy#4875): all integrated
  - 8 bug fixes (Dokploy#4626, Dokploy#4847, Dokploy#4876, Dokploy#4877, Dokploy#4911, Dokploy#4924, Dokploy#4929, Dokploy#4931): all integrated
  - 2 AI custom provider (Dokploy#4882): integrated
  - 1 icon management (Dokploy#4932): integrated with serviceNetworks stripped (Dokploy#3774 not picked)
  - SOS / Redis-removal / multi-language cleanup: rejected

After this commit, GitHub will no longer list these upstream commits
as 'ahead/behind' pending sync. Future upstream changes still need
to be re-evaluated per docs/design-docs/2026-07-29-upstream-sync-policy.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants