Project

Profile

Help

Issue #4903

closed

python bindings are unable to nullify repository description

Added by mdellweg over 5 years ago. Updated about 4 years ago.

Status:
CLOSED - WONTFIX
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:
API Bindings
Sprint:
Quarter:

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

test_repo_bindings.py (1.2 KB) test_repo_bindings.py Reproducer mdellweg, 06/03/2019 08:55 PM
Actions #1

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.

Actions #2

Updated by amacdona@redhat.com over 5 years ago

  • Triaged changed from No to Yes
  • Sprint set to Sprint 54
Actions #3

Updated by ttereshc over 5 years ago

  • Sprint changed from Sprint 54 to Sprint 55
Actions #4

Updated by dkliban@redhat.com over 5 years ago

  • Sprint changed from Sprint 55 to Sprint 56
Actions #5

Updated by rchan over 5 years ago

  • Sprint changed from Sprint 56 to Sprint 57
Actions #6

Updated by rchan over 5 years ago

  • Sprint changed from Sprint 57 to Sprint 58
Actions #7

Updated by fao89 over 5 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fao89
Actions #8

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

Actions #9

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.

Actions #10

Updated by fao89 over 5 years ago

  • Sprint deleted (Sprint 58)
Actions #11

Updated by dkliban@redhat.com about 4 years ago

  • Status changed from NEW to CLOSED - WONTFIX

Please use the workaaround from the above comment.

Also available in: Atom PDF