Issue #4903

python bindings are unable to nullify repository description

Added by mdellweg over 1 year ago. Updated 4 months ago.

Start date:
Due date:
Estimated time:
2. Medium
Platform Release:
Sprint Candidate:
API Bindings


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. (1.2 KB) Reproducer mdellweg, 06/03/2019 08:55 PM


#1 Updated by over 1 year 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.

#2 Updated by over 1 year ago

  • Triaged changed from No to Yes
  • Sprint set to Sprint 54

#3 Updated by ttereshc over 1 year ago

  • Sprint changed from Sprint 54 to Sprint 55

#4 Updated by over 1 year ago

  • Sprint changed from Sprint 55 to Sprint 56

#5 Updated by rchan over 1 year ago

  • Sprint changed from Sprint 56 to Sprint 57

#6 Updated by rchan over 1 year ago

  • Sprint changed from Sprint 57 to Sprint 58

#7 Updated by fao89 over 1 year ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fao89

#8 Updated by fao89 over 1 year 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,
            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,
            return obj.isoformat()

        if isinstance(obj, dict):
            obj_dict = obj
            # 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:
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":, "description": repository.description})

it will work as expected

#9 Updated by fao89 over 1 year ago

  • Status changed from ASSIGNED to NEW
  • Assignee deleted (fao89)

There is an open issue for it:
So for now, as a workaround we can use dict instead of models objects, as shown in the previous note.

#10 Updated by fao89 over 1 year ago

  • Sprint deleted (Sprint 58)

#11 Updated by 4 months ago

  • Status changed from NEW to CLOSED - WONTFIX

Please use the workaaround from the above comment.

Please register to edit this issue

Also available in: Atom PDF