Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inflection is not performed by AutoPrefetchMixin for included resources #871

Closed
@masda70

Description

@masda70

On v4.0.0, inflection is not performed by the AutoPrefetchMixin for included resources, contrary to the JSONRenderer.

Suppose the following data model, serializers and viewsets:

from django.db import modelsfrom rest_framework import viewsets, mixinsfrom rest_framework_json_api import views, serializersclass Album(models.Model):    title = models.TextField()class Track(models.Model)    title = models.TextField()    is_part_of = models.ManyToManyField(Album)class AlbumSerializer(serializers.ModelSerializer):    class Meta:        model = Album        fields = ["title"]class TrackSerializer(serializers.ModelSerializer):    class Meta:        model = Track        fields = ["title", "is_part_of"]    included_serializers = {        "is_part_of": AlbumSerializer,    }
class Track(    views.AutoPrefetchMixin,    views.RelatedMixin,    mixins.ListModelMixin,    viewsets.GenericViewSet):    serializer_class = serializers.TrackSerializer    queryset = Track.objects.all()

BothGET /tracks?include=is-part-of andGET /tracks?include=isPartOf correctly return the set all of tracks along with their albums' titles embedded within theincluded section of the response.

However, prefetch of the tracks' related album objects is not performed, as one would expect fromviews.AutoPrefetchMixin.

My workaround is to performGET tracks?include=is_part_of, which returns the same thing as the above two queries but also performs prefetching.

My investigation has shown me that theAutoPrefetchMixin does not perform inflection of the result ofget_included_resources that it uses to create the argument passed toprefetch_related. The JSONRenderer does the following instead:

        included_resources = copy.copy(included_resources)        included_resources = [inflection.underscore(value) for value in included_resources]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp