Actions
Issue #3966
closedRepository Version OpenAPI response schema is wrong
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Quarter:
Description
The OpenAPI schema for the response of Repository Version contains 2 required fields: 'add_content_units' and 'remove_content_units'. The live docs are wrong and the generated bindings produce the following traceback:
repo_version = api.repositories_versions_read(repository.latest_version_href)
Traceback (most recent call last):
File "devel/pulp3_python_client_example/test_bindings.py", line 46, in <module>
repo_version = api.repositories_versions_read(repository.latest_version_href)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api/pulp_api.py", line 6760, in repositories_versions_read
(data) = self.repositories_versions_read_with_http_info(repository_version_href, **kwargs) # noqa: E501
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api/pulp_api.py", line 6838, in repositories_versions_read_with_http_info
collection_formats=collection_formats)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 322, in call_api
_preload_content, _request_timeout)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 161, in __call_api
return_data = self.deserialize(response_data, response_type)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 233, in deserialize
return self.__deserialize(data, response_type)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 272, in __deserialize
return self.__deserialize_model(data, klass)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 615, in __deserialize_model
instance = klass(**kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/models/repository_version.py", line 93, in __init__
self.add_content_units = add_content_units
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/models/repository_version.py", line 291, in add_content_units
raise ValueError("Invalid value for `add_content_units`, must not be `None`") # noqa: E501
ValueError: Invalid value for `add_content_units`, must not be `None`
Actions
Problem: OpenAPI schema for RepositoryVersion 'retrieve' is wrong
Solution: Create separate serializers for 'create' operation
The problem was that we had a single serializer for both GET and POST. DRF was able to distinguish which fields were to be used for accepting POST body params and which fields to use when serializing for a GET response. DRF knows this because some fields are 'write_only'. However, the drf_yasg library we use for generating OpenAPI schema does not take into account the 'write_only' attribute of a field. As a result when it was using the serializer to generate a schema for the GET response it was including the 'write_only' fields.
This patch introduces a new serializer that is only used for the 'create' operation of the RepositoryVersion ViewSet. This serializer is only used to inspect the inbound data in the POST body. It is not used for the response. The response is generated using the OperationPostponed serializer.
closes: #3966 https://pulp.plan.io/issues/3966