Skip to content

Fix nullable Mongo list container validation - #30568

Merged
SevInf merged 1 commit into
mainfrom
fix-mongo-nullable-list-containers
Oct 1, 2026
Merged

SevInf merged 1 commit into
mainfrom
fix-mongo-nullable-list-containers

Conversation

@StevenMcClankerton

@StevenMcClankerton StevenMcClankerton commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Linked issue

Follow-up to #30051, found during fresh consumer QA. No Linear ticket, per the original project direction.

At a glance

optionalStrings String[]?
optionalNullableStrings String?[]?

Both fields now admit an explicit null container in Mongo; only the second admits null elements. Previously, omission worked but an explicit null container failed database validation.

Summary

Make Mongo collection validation honor the existing nullable-list contract and generated TypeScript types, independently of element nullability.

Decision

This PR changes all three list-container branches in Mongo BSON schema derivation to emit bsonType: ['null', 'array'] only when the container is nullable. Required containers remain array-only; item schemas and required-field membership remain unchanged. It also corrects the two ADR 248 examples to use the supported .optional() method.

Notes for the reviewer

  • The large generated diff is two new content-addressed retail-store snapshot pairs. Their semantic changes are the nullable products.embedding validator and its storage hash. Existing historical snapshots are retained.
  • The current retail-store contract pair and five files in its disposable example migration chain were regenerated using canonical fixture tooling, with one import-order adjustment required by the new hash. This is fixture maintenance, not guidance to rewrite applied production migrations.
  • The Mongo family's older migration-contract fixture remains a valid historical input. Its tests derive their expected hash from that fixture, rather than comparing it with freshly emitted retail-store output; all family tests pass unchanged.
  • No domain/framework contract schema or extension SPI changes, SQL behavior changes, compatibility shims, or security-check bypasses. Project close-out files and the retrospective remain local and are not included; this PR does not close or delete the project.
  • At verification, origin/main was c45a0741fc4fb889b63278cf49fe235aa7ad126f, one commit ahead of the branch base. Its shared-code change adds a PSL diagnostic code; there are no overlapping changed files, and git merge-tree --write-tree HEAD origin/main succeeds. No rebase was performed.

How it fits together

  1. BSON derivation applies container nullability consistently to scalar/enum, value-object, and unconstrained-codec lists.
  2. Unit matrices and interpreter assertions verify the exact container and item schemas independently.
  3. The new real-Mongo regression derives validators through production authoring contributions and applies them through the migration planner/runner. Its 56 distinct cases cover insert and update, omission, explicit null, null elements, empty arrays, wrong container types, and wrong item types, with whole-document assertions and validation error 121 checks.

Compatibility and upgrade

The new app upgrade fragment directs consumers to re-emit their current contract pair and apply a new validator migration before writing null containers. Applied production migrations and their snapshots must remain unchanged. Runtime deployment alone cannot update collection validators.

The fragment separately describes regeneration for disposable example fixtures. A disposable checkout restored examples/ from actual origin/main, ran pnpm fixtures:emit, organized the changed migration imports, and reproduced this commit's example files exactly. Example tests were untouched and passed afterward. No extension declaration is needed because no extension code or SPI changed.

Testing performed

Finalization checks on the committed content:

  • pnpm --filter './packages/2-mongo-family/**' test: 2,309 tests across 142 files, including emitter (65) and family (211); all passed.
  • pnpm --filter retail-store test: 55 tests / 13 files passed; local typecheck and lint passed. The upgrade rehearsal also passed all 55 tests.
  • pnpm fixtures:check: passed twice with generated output staged; no subsequent fixture drift. Upgrade rehearsal source equality and unchanged-test checks passed.
  • pnpm lint: 102/102 tasks passed after sorting the generated migration imports.
  • pnpm typecheck --continue --concurrency=4: 170/171 tasks passed. Only prisma7-adoption#typecheck failed: the NixOS Prisma 7 schema-engine checksum URL returns 404 Not Found. No checksum or engine-download bypass was used.
  • pnpm lint:deps, lint:code, lint:rules, lint:rules:symlinks, lint:skills, lint:rules:footprint, lint:docs, lint:manifests, lint:workflows, lint:casts, lint:throws, lint:framework-vocabulary, lint:consumer-internal-imports, lint:legacy-name, lint:vitest-timeouts, lint:publishability, and check:error-reference: passed.
  • Committed-ref check:upgrade-coverage --mode pr --prev origin/main --head HEAD and check:release-notes --mode pr --prev origin/main: passed. DCO sign-off and whitespace checks passed.

Earlier verification on the same implementation, before accepting the generated fixtures:

  • pnpm build: 87/87 tasks passed.
  • PSL and public Mongo facade unit suites: 302 + 154 = 456 tests passed (PSL overlaps the family total above).
  • pnpm --filter integration-tests test test/mongo: 712 reported tests / 112 reported files passed across configured projects. Explicit --project integration execution of the new regression passed 56 distinct cases; these counts are not additive.
  • Failing-first regression: 52 passed, four explicit-null scalar/value-object cases failed before rebuilding the fix.
  • Fresh public-consumer emission and live Mongo writes: nullable containers accepted, nullable elements accepted, and strict null elements still rejected with error 121; complete stored-document assertions passed. This scoped manual probe exercises emitted validators/direct-driver writes, not Mongo ORM execution.

Skill update

No new public API or workflow is introduced: this corrects validation of existing nullability syntax. Consumer action is documented in the independent pending app upgrade fragment; general authoring skills require no change.

Checklist

  • All commits are signed off (git commit -s).
  • CONTRIBUTING.md read; the change is scoped to one logical concern.
  • Tests updated with failing-first unit and real-database regressions.
  • Linear-prefixed title: not applicable; explicitly requested without a ticket.
  • Skill update section completed.

Alternatives considered

  • Keeping nullable lists omission-only would leave generated types and explicit-null database behavior inconsistent.
  • Relaxing item schemas would change element nullability unnecessarily; only the container BSON type is widened.
  • Rewriting applied production migrations would invalidate migration history; consumers instead add a validator migration, while repository-owned disposable fixtures use canonical regeneration.

Summary by CodeRabbit

  • Bug Fixes
    • Nullable lists now accept null as the list value, independently of whether their individual elements may be null.
    • Updated the retail-store example to allow a product’s embedding field to be null or an array of numbers.
  • Documentation
    • Clarified how to update contracts and handle database migrations when adopting nullable list containers.

@StevenMcClankerton
StevenMcClankerton requested a review from a team as a code owner October 1, 2026 17:11
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (2)
docs/README.md — configured
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: prisma/orm/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 63499c20-4f65-4925-b6fb-c0ef8de7fb2a

📥 Commits

Reviewing files that changed from the base of the PR and between c45a074 and 16e24a4.

📒 Files selected for processing (19)
  • docs/architecture docs/adrs/ADR 248 - List cardinality has independent container and element nullability.md
  • examples/retail-store/migrations/app/20260513T0508_backfill_product_status/migration.json
  • examples/retail-store/migrations/app/20260513T0508_backfill_product_status/migration.ts
  • examples/retail-store/migrations/app/20260513T0508_backfill_product_status/ops.json
  • examples/retail-store/migrations/app/20260628T0931_add_product_status_order_type_enums/migration.json
  • examples/retail-store/migrations/app/20260628T0931_add_product_status_order_type_enums/migration.ts
  • examples/retail-store/migrations/snapshots/41bd5540ea833c009b5eacf6db7d489e88bdd5062554398ba8aa2657fa19d27e/contract.d.ts
  • examples/retail-store/migrations/snapshots/41bd5540ea833c009b5eacf6db7d489e88bdd5062554398ba8aa2657fa19d27e/contract.json
  • examples/retail-store/migrations/snapshots/9af6d90aaa4cd03bf7eb2040a1c1b5c1225a2b33883ea3d0552f312f4684f8dc/contract.d.ts
  • examples/retail-store/migrations/snapshots/9af6d90aaa4cd03bf7eb2040a1c1b5c1225a2b33883ea3d0552f312f4684f8dc/contract.json
  • examples/retail-store/src/contract.d.ts
  • examples/retail-store/src/contract.json
  • packages/2-mongo-family/2-authoring/contract-psl/src/derive-json-schema.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema.enum.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema.target-types.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.test.ts
  • test/integration/test/mongo/target-runner/runner-nullable-lists.test.ts
  • upgrade-instructions/pending/mongo-nullable-list-containers/app/instructions.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Nullable many-valued fields now generate schemas that allow the list container to be null, independently of whether list elements may be null. Tests, retail-store contracts and migration snapshots, and upgrade instructions reflect the updated behavior.

Changes

Nullable list schema generation

Layer / File(s) Summary
Derive nullable-list schemas
packages/2-mongo-family/2-authoring/contract-psl/src/derive-json-schema.ts, packages/2-mongo-family/2-authoring/contract-psl/test/*, docs/architecture docs/adrs/ADR 248 - List cardinality has independent container and element nullability.md
Schema derivation allows nullable list containers for untyped, scalar, and value-object fields. Tests cover combinations of container and element nullability, and the ADR examples use .optional() for whole-list nullability.
Verify Mongo list validation
test/integration/test/mongo/target-runner/runner-nullable-lists.test.ts
Integration tests cover inserts and updates for required and optional string and object lists, including null containers and elements, omitted fields, and invalid values.
Update retail-store contracts and migrations
examples/retail-store/src/contract.*, examples/retail-store/migrations/snapshots/*/contract.*, examples/retail-store/migrations/app/20260513T0508_backfill_product_status/*, examples/retail-store/migrations/app/20260628T0931_add_product_status_order_type_enums/*, upgrade-instructions/pending/mongo-nullable-list-containers/app/instructions.md
Retail-store validators now allow embedding to be null or an array of doubles. Contract hashes, snapshots, and migration references are updated. Upgrade instructions describe contract regeneration and migration handling.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: wmadden-electric

Merge Risk: ⚪ Minimal · up to 16e24

Nullable Mongo list fields can now hold an explicit null while required lists still reject it, and element rules are unchanged. Existing databases need a new validator migration before they write null lists, as the upgrade instructions describe. No blocking issues were found.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 16e24

The change permits explicit null containers already allowed by nullable-list declarations while preserving required fields and element validation. Existing databases require a migration before using this behavior. No concrete security regression was established, but interrupted upgrades and rollback after null writes are not demonstrated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The added accepted input is an explicit null container in a schema-declared nullable list field, including nested value-object fields. Its effective database scope depends on where regenerated validators are deployed; production tenant, asset, and environment exposure was not supplied.

Trust Boundaries and Controls

  • observed — The inspected contract changes do not add operations or capabilities. The database validation boundary remains active: the integration assertions require error 121 for invalid containers or items and unchanged stored state after rejected inserts and updates.

Resilience and Maintainability Implications

  • observed — The new integration coverage demonstrates sequential accepted and rejected writes after one successful initial migration. It does not exercise an existing-database upgrade, interruption, concurrent migration or writes, recovery, or rollback after explicit-null persistence.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 11 files. (8 skipped: 8… 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 and concisely describes the main change: correcting validation for nullable MongoDB list containers.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 11 files. (8 skipped: 8 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30568

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30568

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30568

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30568

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30568

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30568

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30568

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30568

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30568

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30568

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30568

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30568

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30568

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30568

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30568

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30568

commit: 16e24a4

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 214.59 KB (0%)
postgres / emit 192.46 KB (0%)
mongo / no-emit 195.96 KB (0%)
mongo / emit 175.18 KB (0%)
cf-worker / no-emit 270.45 KB (0%)
cf-worker / emit 245.63 KB (0%)

@SevInf
SevInf added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit 84b3bb6 Oct 1, 2026
27 checks passed
@SevInf
SevInf deleted the fix-mongo-nullable-list-containers branch October 1, 2026 18:31
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.

2 participants