Jump to solution
Verify

The Fix

Adds support for the 'propertyNames' keyword in JSON schema, which is causing issues when converting Pydantic models with Enums into JSON.

Based on closed pydantic/pydantic issue #11337 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -958,17 +958,26 @@ def dict_schema(self, schema: core_schema.DictSchema) -> JsonSchemaValue: json_schema: JsonSchemaValue = {'type': 'object'} - keys_schema = self.generate_inner(schema['keys_schema']).copy() if 'keys_schema' in schema else {} + keys_schema = self.resolve_schema_to_update( + self.generate_inner(schema['keys_schema']).copy() if 'keys_schema' in schema else {}
repro.py
pydantic version: 2.10.6 pydantic-core version: 2.27.2 pydantic-core build: profile=release pgo=false install path: C:\Users\Micah\AppData\Local\pypoetry\Cache\virtualenvs\ds-utils-k-EZB9sN-py3.12\Lib\site-packages\pydantic python version: 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] platform: Windows-10-10.0.19045-SP0 related packages: fastapi-0.115.7 pyright-1.1.329 typing_extensions-4.12.2 commit: unknown
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Apply the official fix\nAdds support for the 'propertyNames' keyword in JSON schema, which is causing issues when converting Pydantic models with Enums into JSON.\nWhen NOT to use: This fix should not be used if the application requires the 'propertyNames' keyword for valid JSON schemas.\n\n

Why This Fix Works in Production

  • Trigger: Disable support for "propertyNames" in 'model_json_schema()'
  • Mechanism: The 'propertyNames' keyword in JSON schema is causing parsing failures in MongoDB
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The 'propertyNames' keyword in JSON schema is causing parsing failures in MongoDB
  • Production symptom (often without a traceback): Disable support for "propertyNames" in 'model_json_schema()'

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Could you please provide a MRE giving the JSON Schema that fails?”
@Viicos · 2025-01-24 · source

Failure Signature (Search String)

  • Disable support for "propertyNames" in 'model_json_schema()'
  • I am trying to convert a Pydantic model with ENums into JSON for updating the schema of a collection in MongoDB. The issue started occuring since this PR was merged:
Copy-friendly signature
signature.txt
Failure Signature ----------------- Disable support for "propertyNames" in 'model_json_schema()' I am trying to convert a Pydantic model with ENums into JSON for updating the schema of a collection in MongoDB. The issue started occuring since this PR was merged: https://github.com/pydantic/pydantic/pull/10478

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Disable support for "propertyNames" in 'model_json_schema()' I am trying to convert a Pydantic model with ENums into JSON for updating the schema of a collection in MongoDB. The issue started occuring since this PR was merged: https://github.com/pydantic/pydantic/pull/10478

Minimal Reproduction

repro.py
pydantic version: 2.10.6 pydantic-core version: 2.27.2 pydantic-core build: profile=release pgo=false install path: C:\Users\Micah\AppData\Local\pypoetry\Cache\virtualenvs\ds-utils-k-EZB9sN-py3.12\Lib\site-packages\pydantic python version: 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] platform: Windows-10-10.0.19045-SP0 related packages: fastapi-0.115.7 pyright-1.1.329 typing_extensions-4.12.2 commit: unknown

Environment

  • Pydantic: 2

What Broke

Users experience errors when converting Pydantic models with Enums into JSON for MongoDB.

Why It Broke

The 'propertyNames' keyword in JSON schema is causing parsing failures in MongoDB

Fix Options (Details)

Option A — Apply the official fix

Adds support for the 'propertyNames' keyword in JSON schema, which is causing issues when converting Pydantic models with Enums into JSON.

When NOT to use: This fix should not be used if the application requires the 'propertyNames' keyword for valid JSON schemas.

Fix reference: https://github.com/pydantic/pydantic/pull/10478

Last verified: 2026-02-11. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the application requires the 'propertyNames' keyword for valid JSON schemas.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.