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

key name in dict accidentally is the same as method/function name #2244

Closed
Labels
Milestone
@Catstyle

Description

@Catstyle

this is the situation 1 mentioned in#2237

In [1]: from rest_framework import serializersIn [2]: class Foo(serializers.Serializer):    items = serializers.ListSerializer(child=serializers.IntegerField())   ...:     In [3]: s = Foo({'items': [1, 2, 3]})In [4]: s.data---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-4-b0eddb6f5f12> in <module>()----> 1 s.data.../rest_framework/serializers.pyc in data(self)    420     @property    421     def data(self):--> 422         ret = super(Serializer, self).data    423         return ReturnDict(ret, serializer=self)    424 .../rest_framework/serializers.pyc in data(self)    175         if not hasattr(self, '_data'):    176             if self.instance is not None and not getattr(self, '_errors', None):--> 177                 self._data = self.to_representation(self.instance)    178             elif hasattr(self, '_validated_data') and not getattr(self, '_errors', None):    179                 self._data = self.to_representation(self.validated_data).../rest_framework/serializers.pyc in to_representation(self, instance)    389                 ret[field.field_name] = None    390             else:--> 391                 ret[field.field_name] = field.to_representation(attribute)    392     393         return ret.../rest_framework/serializers.pyc in to_representation(self, data)    520         iterable = data.all() if (hasattr(data, 'all')) else data    521         return [--> 522             self.child.to_representation(item) for item in iterable    523         ]    524 TypeError: 'builtin_function_or_method' object is not iterable
fields.py  62         try:                                                                      63             instance = getattr(instance, attr)                                    64         except ObjectDoesNotExist:                                                65             return None                                                           66         except AttributeError as exc:                                             67             try:                                                                  68                 return instance[attr]                                             69             except (KeyError, TypeError, AttributeError):                         70                 raise exc

it just return dict.items instead of dict['items'], should it check instance[attr] first?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp