Required properties removed from component if PATCH processed first #249
Labels
bug
Something isn't working
fix confirmation pending
issue has been fixed and confirmation from issue reporter is pending
Describe the bug
I drilled down into the source to find what was causing issues with
required
properties in some_Request
components whenCOMPONENT_SPLIT_REQUEST
is set toTrue
: #243I believe I've finally found the issue. In short, it seems to be related to a registered component for a
PATCH
request being re-used for aPOST
request when they are not strictly equivalent. This issue is very hard to reproduce properly, but I will try to describe here.You must process an unrelated
PATCH
request that happens to use this component in the body prior to processing this component in aPOST
request context.To Reproduce
COMPONENT_SPLIT_REQUEST = True
COMPONENT_SPLIT_PATCH = True
Note that the bug will not occur if a POST request is processed first for this component. I have confirmed the behavior by placing a breakpoint here.
When you hit the breakpoint, manually call
self._map_serializer(serializer, direction)
to see the generated schema. As expected,required
properties are removed from thePatchedXRequest
component.The issue occurs when an unrelated
PATCH
method is processed first, and this causesXSerializer
to be added to the component registry.y-view
that usesXSerializer
as some participating componentx-view
) will hit the component registry and pull the first generated schema that does not contain the required fields!This schema is produced. Note the missing required fields.
I've tried to add as much reproduction as I can, but I hope the gist is clear enough. Basically, sometimes components are first registered in some kind of
PATCH
context, which excludes required fields, and when it comes time to create the Request component for the POST request, it finds the existing component in the registry that does not have the required fields. If_map_serializer
is called again manually, it produces different schema than that returned from the component registry.I've finally gotten a repro, but I cannot tell what part of it triggers the behavior. Something I've noticed is that sometimes
_Request
components are generated for serializers that are always read only. The components are unused in the generated spec.I can't paste my original source unfortunately but please let me know if you need anything else! Thank you!
The text was updated successfully, but these errors were encountered: