fix: preserve falsy literal default values (false, 0, '') during contract canonicalization#804
fix: preserve falsy literal default values (false, 0, '') during contract canonicalization#804prisma-gremlin[bot] wants to merge 1 commit into
Conversation
…ract canonicalization
The omitDefaults walk in canonicalization.ts treats false as a default
value to strip (for nullable:false, generated:false, etc.). This caused
default: { kind: 'literal', value: false } to lose its value key during
emit, producing { kind: 'literal' } without a value property — which
fails contract validation with PN-CLI-4003.
Add isDefaultLiteralValue guard: when key === 'value' and the parent
path element is 'default', skip the default-omission logic so that
falsy values (false, 0, '') inside literal defaults are always
preserved.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR fixes canonicalization to preserve falsy literal default values on column definitions. A new predicate detects when the current key is ChangesPreserve literal default values in canonicalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
Problem
@default(false)loses itsvalueon emit, producing{"kind":"literal"}with novalueproperty. This fails contract validation with PN-CLI-4003.@default(true)works correctly becausetrueis not treated as a default-omission candidate.Root Cause
In
canonicalization.ts, theomitDefaultswalk usesisDefaultValue()to identify values that should be stripped from the JSON envelope.isDefaultValue(false)returnstrue— which is correct for fields likenullable: falseandgenerated: falsethat are indeed defaults. However, when the walk reachesvalue: falseinsidedefault: { kind: "literal", value: false }, the same logic strips thevaluekey, producing the invalid{ kind: "literal" }.Fix
Add an
isDefaultLiteralValueguard inomitDefaults: whenkey === "value"and the parent path element is"default", skip the default-omission logic so that falsy values (false,0,"") inside literal defaults are always preserved.Changed files:
packages/1-framework/0-foundation/contract/src/canonicalization.ts— addisDefaultLiteralValueguardpackages/1-framework/0-foundation/contract/test/canonicalization.test.ts— add tests forvalue: false,value: 0,value: ""packages/1-framework/3-tooling/emitter/test/canonicalization.test.ts— add tests forvalue: false,value: 0Summary by CodeRabbit
Release Notes
Bug Fixes
Tests