Fix JSON schema provider crash for Dict/List fields (#2037) - #2038
Conversation
|
@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: 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! |
|
@jenkins-plone-org please run jobs |
20f7e5b to
d9ff170
Compare
|
I have refined the fix to follow a more localized approach as discussed. Refined Changes:
The implementation is now robust against the reported crash while preserving the strictness of the base classes. |
|
@jenkins-plone-org please run jobs |
|
Thank you for your review @davisagli, nevertheless, applying your suggestion, the Collection type information is not properly rendered and it crashes. The reason for the defensive code in my PR is that standard Plone Collections use Currently, I agree we shouldn't hide errors for specific field types, but If you still think that the defensive strategy doesn't feel right, I could implement a more specific adapter for This way, we can have the adapter approach for this kind of fields while raising |
|
@erral I see. I think we should update DefaultJsonSchemaProvider to return None from Please also add a test for the case you're talking about (Dict with value_type=schema.Field()) |
…n sub-types are missing (#2037)
d2e6305 to
40e3941
Compare
|
Thanks, that makes sense! |
|
@jenkins-plone-org please run jobs |
|
I have no clue what you're doing here, but I happened to run tests on a buildout with local checkouts and that threw me a nasty error: I don't know if that's an error in my specific setup or a more generic error condition not caught yet. |
|
plone.app.blocks has its own RichTextValue adapter, like the one we have added to plone.restapi: see https://github.com/plone/plone.app.blocks/blob/master/src/plone/app/blocks/configure.zcml#L27-L30 We didn't catch this because as plone.app.blocks is not part of plone core neither our own tests nor Jenkins caught this. I am opening an issue in plone.app.blocks referencing this PR. |
|
The relevant issue is #1584 not this one. |
This PR fixes a crash in the JSON schema providers for Dict and List fields when they are defined without specifying sub-types (
key_typeorvalue_type).In
zope.schema, these sub-types default toNone. The previous implementation was unconditionally attempting to adapt theseNonevalues toIJsonSchemaProvider, leading to aComponentLookupError.Changes:
getMultiAdapterwithqueryMultiAdapterand added safety checks forkey_typeandvalue_typeinDictJsonSchemaProviderandCollectionJsonSchemaProvider.src/plone/restapi/tests/test_types.py.Fixes #2037