Skip to content

fix(contract): preserve empty model fields - #30003

Open
Shgit29 wants to merge 2 commits into
prisma:mainfrom
Shgit29:fix/1070-preserve-empty-model-fields
Open

fix(contract): preserve empty model fields#30003
Shgit29 wants to merge 2 commits into
prisma:mainfrom
Shgit29:fix/1070-preserve-empty-model-fields

Conversation

@Shgit29

@Shgit29 Shgit29 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Fixes #30130

Refs prisma/prisma-next#1070

Summary

Field-less variant models correctly produce fields: {} during PSL interpretation, but contract canonicalization removed that empty object even though fields is a required model property.

This change preserves empty model fields during canonicalization so emitted contracts remain structurally valid.

Testing performed

  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm test:packages
  • Targeted @internal/contract tests
  • Targeted @internal/mongo-contract-psl tests
  • Targeted Mongo emitter tests
  • git diff --check

The full package suite had unrelated transient failures under load; the affected package suites passed when rerun separately.

Skill update

n/a — internal only

Checklist

  • All commits are signed off (git commit -s) per the DCO. The DCO status check will block merge if any commit is missing a Signed-off-by: trailer.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (or n/a if the change is doc-only / refactor with no behavioural delta).
  • The PR title is in TML-NNNN: <sentence-case title> form (Linear ticket prefix + concise title naming the concrete deliverable). See .claude/skills/create-pr/SKILL.md for the full convention.
  • The Skill update section above is filled in (or stated n/a — internal only).

Notes for the reviewer

This issue was originally reported as prisma/prisma-next#1070 and has now been re-filed in the current repository as #30130 after Prisma Next moved to prisma/prisma as Prisma ORM v8.

The fix is applied in generic contract canonicalization rather than the Mongo-specific canonicalization hook because fields is a required model property at the framework contract level.

Summary by CodeRabbit

Bug Fixes

  • Preserved empty model-field containers during contract canonicalization, preventing field-less variants from losing their expected structure.
  • Ensured field-less polymorphic variants remain compatible with Mongo schema validation.
  • Maintained consistent canonicalized output without changing existing runtime behavior.

Tests

  • Added regression coverage confirming field-less variants retain fields: {} before and after canonicalization and pass Mongo schema validation.

@Shgit29
Shgit29 requested a review from a team as a code owner August 12, 2026 21:36
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 81ce2333-9e39-4385-bfee-9009c4e10734

📥 Commits

Reviewing files that changed from the base of the PR and between ca8fe14 and 64df122.

📒 Files selected for processing (2)
  • packages/1-framework/0-foundation/contract/src/canonicalization.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
  • packages/1-framework/0-foundation/contract/src/canonicalization.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Canonicalization preserves empty fields objects for field-less polymorphic model variants. A regression test verifies preservation through canonicalization and Mongo schema validation.

Changes

Field-less variant contract handling

Layer / File(s) Summary
Preserve empty model-field containers
packages/1-framework/0-foundation/contract/src/canonicalization.ts
Canonicalization recognizes model field paths and preserves matching empty containers during default omission. Type assertions use blindCast, and object-key sorting retains its runtime behavior.
Validate field-less variants
packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
A regression test verifies that a field-less Note variant retains fields: {} before and after canonicalization and passes MongoContractSchema validation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 64df1

The change preserves required empty model fields in emitted contracts and is covered by targeted tests; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: preserving empty contract model fields. It is concise and specific.
Linked Issues check ✅ Passed The canonicalization change preserves fields: {} for field-less variant models. The regression test verifies preservation before and after canonicalization and confirms Mongo schema validation. This s…
Out of Scope Changes check ✅ Passed The changes are limited to canonicalization behavior, related type-cast refactoring, and regression coverage. All changes support the linked issue objective.
Full details: Linked Issues check

Explanation

The canonicalization change preserves fields: {} for field-less variant models. The regression test verifies preservation before and after canonicalization and confirms Mongo schema validation. This satisfies issue #30130.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts`:
- Line 153: Update both assertions in the polymorphism tests around
modelsOf(ir)['Note'] to verify that fields is exactly an empty object rather
than merely matching an empty subset. Replace each toMatchObject({ fields: {} })
assertion with toHaveProperty('fields', {}) or extract fields and compare it
with toEqual({}).
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 080c171e-457b-4072-9ade-cf6ee25e7889

📥 Commits

Reviewing files that changed from the base of the PR and between c332c67 and ff9ac5d.

📒 Files selected for processing (2)
  • packages/1-framework/0-foundation/contract/src/canonicalization.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts

@Shgit29

Shgit29 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@wmadden I noticed you’ve worked on the contract canonicalization path, so you may be a good person to review this. This fixes prisma/prisma-next#1070 by preserving required empty model fields during canonicalization. I’ve also addressed the feedback on the regression assertions, and the targeted tests pass. Thanks!

@Shgit29
Shgit29 force-pushed the fix/1070-preserve-empty-model-fields branch from 3f44102 to 4246b65 Compare August 17, 2026 06:57
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Shgit29
Shgit29 force-pushed the fix/1070-preserve-empty-model-fields branch from 4246b65 to 209a775 Compare August 18, 2026 15:15
@Shgit29
Shgit29 force-pushed the fix/1070-preserve-empty-model-fields branch from 209a775 to 807a193 Compare August 25, 2026 16:37
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Shgit29

Shgit29 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@wmadden I re-filed the original Prisma Next issue in the current repo as #30130 and updated this PR to link to it. The bug still reproduces on the latest Prisma ORM v8 main, and the fix/regression test here still applies. Thanks!

Signed-off-by: Saad Hassan <shgit29@gmail.com>
Signed-off-by: Saad Hassan <shgit29@gmail.com>
@Shgit29
Shgit29 force-pushed the fix/1070-preserve-empty-model-fields branch from 807a193 to 64df122 Compare August 28, 2026 17:20
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prisma ORM v8 removes required empty fields from field-less Mongo variant during contract emit

1 participant