Skip to content

Fix JSON schema provider crash for Dict/List fields (#2037) - #2038

Open
erral wants to merge 1 commit into
mainfrom
fix-dict-json-schema-crash
Open

Fix JSON schema provider crash for Dict/List fields (#2037)#2038
erral wants to merge 1 commit into
mainfrom
fix-dict-json-schema-crash

Conversation

@erral

@erral erral commented Jul 30, 2026

Copy link
Copy Markdown
Member

This PR fixes a crash in the JSON schema providers for Dict and List fields when they are defined without specifying sub-types (key_type or value_type).

In zope.schema, these sub-types default to None. The previous implementation was unconditionally attempting to adapt these None values to IJsonSchemaProvider, leading to a ComponentLookupError.

Changes:

  • Replaced getMultiAdapter with queryMultiAdapter and added safety checks for key_type and value_type in DictJsonSchemaProvider and CollectionJsonSchemaProvider.
  • Added regression tests in src/plone/restapi/tests/test_types.py.

Fixes #2037

@mister-roboto

Copy link
Copy Markdown

@erral thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@erral

erral commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

@jenkins-plone-org please run jobs

@erral
erral force-pushed the fix-dict-json-schema-crash branch from 20f7e5b to d9ff170 Compare July 30, 2026 12:38
@erral

erral commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

I have refined the fix to follow a more localized approach as discussed.

Refined Changes:

  • Restored DefaultJsonSchemaProvider and the general properties loop in utils.py to their original strict states, maintaining standard registration and architectural patterns.
  • Implemented try...except NotImplementedError blocks specifically within DictJsonSchemaProvider and CollectionJsonSchemaProvider.
  • This ensures that if a nested field (like the generic schema.Field() in standard Plone Collections) lacks a specialized schema provider, it is gracefully handled (skipped or returned as an empty schema) without crashing the entire endpoint.
  • Maintained regression tests verifying the fix against missing sub-types and generic fields.

The implementation is now robust against the reported crash while preserving the strictness of the base classes.

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.

Collection type information is not properly serialized

2 participants