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.
    • Ensured field-less polymorphic variants remain valid for Mongo schema validation.
  • Tests

    • Added regression coverage for canonicalized field-less variants and Mongo schema compatibility.

@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

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: edf3ee9a-31af-42de-bca3-c10108cc2d36

📥 Commits

Reviewing files that changed from the base of the PR and between 10c57bc and 807a193.

📒 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/1-framework/0-foundation/contract/src/canonicalization.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.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 before and after canonicalization and validates the contract against the Mongo schema.

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 807a1

This change preserves required empty model fields in emitted contracts without introducing an actionable merge-blocking risk; it is merge-ready after normal checks and review.

🚥 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
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving empty model fields during contract canonicalization.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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
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 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!

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