Skip to content

remove ModelViewSet PUT/update() method? #614

Closed
@n2ygk

Description

@n2ygk

DJA uses DRF's viewsets.ModelViewset which includes both PUT (update()) and PATCH (partial_update()) methods. However, the JSONAPI spec only defines PATCH. DJA allows the PUT method. This becomes more apparent when using the new DRF openapi schema generator since it wants to document the PUT method. While DJA implements PUT identically to PATCH, it might be better to not expose this method as the PUT semantics defines a full replacement, which DJA's PUT does not do, since it's just implementing PATCH.

I'm not sure exactly where the PUT method gets defined but I think the change is to replace DRF's ModelViewSet with a DJA-specific version that replaces
DRF's mixins.UpdateModelMixin with one that doesn't define it.

class ModelViewSet(AutoPrefetchMixin,
PrefetchForIncludesHelperMixin,
RelatedMixin,
viewsets.ModelViewSet):

You can see this by doing an OPTIONS http://localhost:8000/blogs/1 as in this example:

{
    "data": {
        "name": "Blog Instance",
        "description": "",
        "renders": [
            "application/vnd.api+json",
            "text/html"
        ],
        "parses": [
            "application/vnd.api+json",
            "application/x-www-form-urlencoded",
            "multipart/form-data"
        ],
        "allowed_methods": [
            "GET",
            "PUT",
            "PATCH",
            "DELETE",
            "HEAD",
            "OPTIONS"
        ],
        "actions": {
            "PUT": {
                "name": {
                    "type": "String",
                    "required": true,
                    "read_only": false,
                    "write_only": false,
                    "label": "Name",
                    "max_length": 100
                },
                "tags": {
                    "type": "GenericField",
                    "relationship_type": "OneToMany",
                    "relationship_resource": "taggedItem",
                    "required": false,
                    "read_only": true,
                    "write_only": false,
                    "label": "Tags",
                    "child": {
                        "type": "Serializer",
                        "required": false,
                        "read_only": true,
                        "write_only": false,
                        "children": {
                            "tag": {
                                "type": "Slug",
                                "required": true,
                                "read_only": false,
                                "write_only": false,
                                "label": "Tag",
                                "max_length": 50
                            }
                        }
                    }
                },
                "copyright": {
                    "type": "GenericField",
                    "required": false,
                    "read_only": true,
                    "write_only": false,
                    "label": "Copyright"
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions