Project

Profile

Help

Issue #6702

closed

openapigenerator get_operation multipart workaround causes "cannot instantiate nested serializer as Items" errors

Added by alikins over 4 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 72
Quarter:

Description

While trying to track down travis build errors for https://github.com/ansible/galaxy_ng/pull/68 (such as https://travis-ci.com/github/ansible/galaxy_ng/builds/164529317), the failure would happen in the api client generation stage when it hits the openapi generator page (ie, pulp/api/v3/docs/) which uses openapigenerator.py.

If nested serializers were used, like https://github.com/ansible/galaxy_ng/pull/68/files#diff-ba7c1556b4ef9c4103fb3c3510d91dbcR29, the api client generator would fail with SwaggerGenerationError errors:

"cannot instantiate nested serializer as Items"

Tracking it down, those errors seemed to be caused by https://github.com/pulp/pulpcore/blob/master/pulpcore/app/openapigenerator.py#L319-L330

This is a workaround to force all operations to be introspected as if they supported multipart bodies.

This causes an odd code path through the various drf_yasg inspectors get_request_body_paramaters() methods.

The get_request_body_paramaters calls the inspectors get_request_paramaters().

When this hits the InlineSerializerInspector.get_request_parameters() it calls probe_field_inspectors() which recursively ends up calling it's field_to_swagger_object().

BUT! get_request_paramaters always calls probe_field_inspects() with a swagger_object_type of openapi.Parameter, so the eventual call to InlineSerializerInspector.field_to_swagger_object() will get called with results of _get_partial_types which ends up being 'Items' if swagger_object_type is not a openapi.Schema.

And InlineSerializerInspector.field_to_swagger_object() in that case always hits line ~94: SwaggerGenerationError("cannot instantiate nested serializer as " + swagger_object_type.name)

I think this could potentially related to other issues with nested serializers some folks mentioned in Slack (ie, needing to make any nested serializers be 'read_only=True' to avoid this error.)

Actions #1

Updated by fao89 over 4 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fao89
  • Triaged changed from No to Yes
  • Sprint set to Sprint 72
Actions #2

Updated by pulpbot over 4 years ago

  • Status changed from ASSIGNED to POST

Added by Fabricio Aguiar over 4 years ago

Revision e69480eb | View on GitHub

Only uses multipart when dealing with file fields

https://pulp.plan.io/issues/6702 closes #6702

Actions #3

Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
Actions #4

Updated by dkliban@redhat.com over 4 years ago

  • Sprint/Milestone set to 3.4.0
Actions #5

Updated by dkliban@redhat.com over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF