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

SparseFieldsetsMixin does not use the correct configured JSON_API_FORMAT_FIELD_NAMES #1053

Closed
@jokiefer

Description

@jokiefer

Description of the Bug Report

SparseFieldsetsMixin does not adjust field_names by configured format.

Fix:

classSparseFieldsetsMixin:"""    A serializer mixin that adds support for sparse fieldsets through `fields` query parameter.    Specification: https://jsonapi.org/format/#fetching-sparse-fieldsets    """def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)context=kwargs.get("context")request=context.get("request")ifcontextelseNoneifrequest:sparse_fieldset_query_param="fields[{}]".format(get_resource_type_from_serializer(self)            )try:param_name=next(keyforkeyinrequest.query_paramsifsparse_fieldset_query_param==key                )exceptStopIteration:passelse:fieldset=request.query_params.get(param_name).split(",")# iterate over a *copy* of self.fields' underlying OrderedDict, because we may# modify the original during the iteration.# self.fields is a `rest_framework.utils.serializer_helpers.BindingDict`forfield_name,fieldinself.fields.fields.copy().items():if (field_name==api_settings.URL_FIELD_NAME                    ):# leave self link therecontinue# missing format_value()correct_field_name=format_value(field_name,json_api_settings.FORMAT_FIELD_NAMES)ifcorrect_field_namenotinfieldset:self.fields.pop(field_name)

Checklist

  • Certain that this is a bug (if unsure or you have a question usediscussions instead)
  • Code snippet or unit test added to reproduce bug

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