Project

Profile

Help

Issue #4903

python bindings are unable to nullify repository description

Added by mdellweg 5 months ago. Updated about 1 month ago.

Status:
NEW
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Severity:
2. Medium
Version:
Platform Release:
Blocks Release:
OS:
Backwards Incompatible:
No
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
API Bindings
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:

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.

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

History

#1 Updated by amacdona@redhat.com 5 months 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 amacdona@redhat.com 5 months ago

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

#3 Updated by ttereshc 4 months ago

  • Sprint changed from Sprint 54 to Sprint 55

#4 Updated by dkliban@redhat.com 3 months ago

  • Sprint changed from Sprint 55 to Sprint 56

#5 Updated by rchan 3 months ago

  • Sprint changed from Sprint 56 to Sprint 57

#6 Updated by rchan about 2 months ago

  • Sprint changed from Sprint 57 to Sprint 58

#7 Updated by fabricio.aguiar about 1 month ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fabricio.aguiar

#8 Updated by fabricio.aguiar about 1 month 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

#9 Updated by fabricio.aguiar about 1 month ago

  • Status changed from ASSIGNED to NEW
  • Assignee deleted (fabricio.aguiar)

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.

#10 Updated by fabricio.aguiar about 1 month ago

  • Sprint deleted (Sprint 58)

Please register to edit this issue

Also available in: Atom PDF