fix: resolve OpenAPI 500 error caused by BigInt serialization#3794
Open
vcode-sh wants to merge 1 commit intoDokploy:canaryfrom
Open
fix: resolve OpenAPI 500 error caused by BigInt serialization#3794vcode-sh wants to merge 1 commit intoDokploy:canaryfrom
vcode-sh wants to merge 1 commit intoDokploy:canaryfrom
Conversation
…GracePeriodSwarm Change Drizzle column mode from "bigint" to "number" for stopGracePeriodSwarm across all 6 service schemas. This fixes JSON.stringify failing silently in the @dokploy/trpc-openapi adapter, which unlike the tRPC endpoint does not use superjson and cannot serialize BigInt values. No database migration needed — only the JS representation changes. The values are nanosecond grace periods that fit safely within Number.MAX_SAFE_INTEGER. Also adds onError logging and export const config to the OpenAPI route handler to match the tRPC route and improve debuggability. Fixes Dokploy#3793
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's happening
The OpenAPI endpoint
/api/project.allreturns a 500 Internal Server Error while the tRPC equivalent (/api/trpc/project.all) works perfectly fine. This affects any endpoint that returns services with a non-nullstopGracePeriodSwarmvalue.Root cause
The
stopGracePeriodSwarmcolumn across all 6 service schemas (application, mongo, mariadb, redis, mysql, postgres) uses Drizzle'sbigint("...", { mode: "bigint" }), which returns JavaScriptBigIntvalues from the database.The tRPC route uses
superjsonas its transformer, which handlesBigIntnatively. But the OpenAPI route (@dokploy/trpc-openapi) uses plainJSON.stringify()under the hood — andJSON.stringifythrows aTypeError: Do not know how to serialize a BigIntwhen it encounters one. The error gets caught and returned as a generic 500 with no logging, making it really hard to track down.I confirmed this on my production instance — one of my services has
stopGracePeriodSwarm: 65000000000(65s), and the superjson metadata in the tRPC response explicitly marks it as["bigint"].The fix
Changed the Drizzle column mode from
"bigint"to"number"forstopGracePeriodSwarmacross all 6 service schemas. This is a JS-only change — the database column stays asbigint, no migration needed. The values are nanosecond grace periods that comfortably fit withinNumber.MAX_SAFE_INTEGER(~104 days worth of nanoseconds).The codebase was already converting BigInt→Number everywhere it actually used the value (see
generateConfigContainerindocker/utils.ts), so this just fixes it at the source instead.Also added
onErrorlogging andexport const config(withbodyParser: falseandsizeLimit: "1gb") to the OpenAPI route handler to match the tRPC route — so future errors won't be completely silent.Changes
Schema (6 files):
bigint("stopGracePeriodSwarm", { mode: "bigint" })→{ mode: "number" },z.bigint().nullable()→z.number().nullable()Backend: Removed the now-unnecessary BigInt→Number conversion in
docker/utils.tsFrontend: Updated type guards and form handling in the stop grace period components to use
numberinstead ofbigintOpenAPI handler: Added
onErrorcallback +export const configtopages/api/[...trpc].tsTests: Updated
mechanizeDockerContainertest to usenumbervaluesTesting
serveranddokploypackages passtsc --noEmitcleanlyapplication.real.test.tsare unrelated — they require nixpacks)JSON.stringifysucceeds withnumberwhere it threw withBigIntBigIntvalue that causes the crashFixes #3793
Greptile Summary
Changed
stopGracePeriodSwarmfrom BigInt to number across all service schemas to fix OpenAPI 500 errors. The OpenAPI endpoint usesJSON.stringify()which doesn't handle BigInt values, while tRPC works because it uses superjson. The fix changes Drizzle's column mode from"bigint"to"number"- this is JS-only and requires no database migration since the PostgreSQL column remains bigint. Grace period values (in nanoseconds) safely fit withinNumber.MAX_SAFE_INTEGER.docker/utils.tsConfidence Score: 5/5
Last reviewed commit: d7886fb
(2/5) Greptile learns from your feedback when you react with thumbs up/down!