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

ModelSerializer custom named field source evaluates to True instead of field_name #5389

Closed
@jonsongoffwhite

Description

@jonsongoffwhite

Checklist

  • I have verified that that issue exists against themaster branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to thediscussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to bein the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

  1. Create aModelSerializer including a field inMeta with a custom name (that isn't on the model).
  2. Set the source of the field, inextra_kwargs to a named field within the model.
  3. Initialise the Serializer.

Expected behavior

  • Creates a Serializer with a field with a custom field name, that has it's source as the specified field on the Model.

Actual behavior

  • TypeError: hasattr(): attribute name must be string

Caused by#5138 when accounting for*-sourced fields.

source=extra_field_kwargs.get('source','*')!='*'orfield_name

In the case thatsource is specified AND is not'*',
extra_field_kwargs.get('source', '*') != '*' evaluates toTrue, and thussource = True,
leading to theTypeError

Pull Request with test that fails on master, and fix:#5388

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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