Issue #4903
closedpython bindings are unable to nullify repository description
Description
This probably affects other nullifyable database fields, too.
Using httpie the following commands are both able to set the description to null:
$ http --json PUT :24817/pulp/api/v3/repositories/cebe653e-f8ca-4b2f-acd0-93c5edf32b48/ description:=null name:=\"test_repo\"
$ http --json PATCH :24817/pulp/api/v3/repositories/cebe653e-f8ca-4b2f-acd0-93c5edf32b48/ description:=null
However neither repositories_update (PUT) nor repositories_partial_update (PATCH) are able to perform that transformation.
See the python example in the attachment.
Files
Updated by amacdona@redhat.com over 5 years ago
I think this call should work:
http --json PUT :24817/pulp/api/v3/repositories/cebe653e-f8ca-4b2f-acd0-93c5edf32b48/ name:=\"test_repo\"
The only difference is that for a PUT (which overrides all fields) we don't need to set description to null because it should be overwritten.
Updated by amacdona@redhat.com over 5 years ago
- Triaged changed from No to Yes
- Sprint set to Sprint 54
Updated by dkliban@redhat.com over 5 years ago
- Sprint changed from Sprint 55 to Sprint 56
Updated by fao89 over 5 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to fao89
Updated by fao89 over 5 years ago
openapi-generator creates this method:
def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
else:
# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
for attr, _ in six.iteritems(obj.openapi_types)
if getattr(obj, attr) is not None}
return {key: self.sanitize_for_serialization(val)
for key, val in six.iteritems(obj_dict)}
which is called just before the API call.
On line 29 from here: https://pulp.plan.io/attachments/518581
it sends a repository object, which is treated on sanitize_for_serialization, removing all the attrs with null value.
If we replace line 29 for this:
repositories_api.update(repo_href, {"name": repository.name, "description": repository.description})
it will work as expected
Updated by fao89 over 5 years ago
- Status changed from ASSIGNED to NEW
- Assignee deleted (
fao89)
There is an open issue for it:
https://github.com/OpenAPITools/openapi-generator/issues/1908
So for now, as a workaround we can use dict instead of models objects, as shown in the previous note.
Updated by dkliban@redhat.com about 4 years ago
- Status changed from NEW to CLOSED - WONTFIX
Please use the workaaround from the above comment.