Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception "'BulkListSerializerObject' is not iterable" when using API browser #33

Open
typerlc opened this issue Mar 12, 2015 · 8 comments
Labels

Comments

@typerlc
Copy link

typerlc commented Mar 12, 2015

Posting to a BulkModelViewSet using the DRF api browser causes the following exception to be thrown. NB: the data has already been written to the db successfully before the exception happens:

TypeError at /usage_records/
'BulkListSerializer' object is not iterable
Request Method: POST
Request URL:    http://127.0.0.1:8000/usage_records/
Django Version: 1.7.4
Exception Type: TypeError
Exception Value:    
'BulkListSerializer' object is not iterable
Exception Location: /Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/site-packages/django/template/defaulttags.py in render, line 161
Python Executable:  /Users/richardc/virtualenvs/rating_sytstem/bin/python
Python Version: 2.7.8
Python Path:    
['/Volumes/Data/git/rating-system/rating_system_site',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python27.zip',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/plat-darwin',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/plat-mac',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/lib-tk',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/lib-old',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/lib-dynload',
 '/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/richardc/virtualenvs/rating_sytstem/lib/python2.7/site-packages']
Server time:    Thu, 12 Mar 2015 13:33:11 +1100

The line of code that throws the exception is in the django template library, and it is doing:

values=list(values)

The values object is my serializer object:

Usage_Record_Serializer(context={u'view': <rating_system.views.rest.Usage_Record_ViewSet object>, u'request': <rest_framework.request.Request object>, u'format': None}, data=[{u'event_description': u'Test Event', u'event_value': 122, u'tags': u'PURCHAGES, VISA', u'reference_id': 20, u'external_service': 1, u'external_system': 2, u'external_service_key': u'Etx', u'event_date_time': u'2015-03-02T00:10:13.869285Z'}, {u'event_description': u'Test Event', u'event_value': 122, u'tags': u'PURCHAGES, VISA', u'reference_id': 21, u'external_service': 1, u'external_system': 2, u'external_service_key': u'Etx', u'event_date_time': u'2015-03-02T00:10:13.869285Z'}], many=True)

If I just browse to http://127.0.0.1:8000/usage_records/ again, the template renders correctly, with these new records included.

The basic code is:

class Usage_Record_Serializer(BulkSerializerMixin, serializers.ModelSerializer):
    class Meta(object):
        model = Usage_Record
        list_serializer_class = BulkListSerializer
        read_only_fields = ('id', 'upload_date_time',)

class Usage_Record_ViewSet(BulkModelViewSet):
    queryset = Usage_Record.objects.all()
    serializer_class = Usage_Record_Serializer
    permission_classes = (permissions.IsAuthenticated,)

bulk_router.register(r'usage_records', rest.Usage_Record_ViewSet)

If I use postman or curl, no error is thrown ... so this does seem to be some bad interaction with the DRF api browser.

Any thoughts on why this happens?

Thanks,
Richard

@typerlc
Copy link
Author

typerlc commented Mar 12, 2015

Sorry forgot to add versions:

Python: 2.7.8
Django: 1.7.4
DRF: 3.1.0
DRF-bulk: 0.2

@miki725
Copy link
Owner

miki725 commented Mar 14, 2015

This is known issue, even with DRF2. DRF-bulk for some reason was not compatible with the API browser. Ideally this should not happen. It looks like you already went through some debugging so PRs are welcome!

@miki725 miki725 added the bug label Mar 14, 2015
@arahayrabedian
Copy link

can confirm:
Django==1.7.1
DRF==2.4.4
DRF-bulk==0.2

@chubz
Copy link

chubz commented Apr 22, 2015

confirmed on:
Django==1.8
DRF==3.1.1
DRF-bulk==0.2

@strelnikov
Copy link

any update, guys?
Django==1.6.11
DRF==3.1.1
DRF-bulk==0.2

@liquidpele
Copy link

Looks like if you just add this to the object it works fine...

def __iter__(self):
    return self

def next(self):
    raise StopIteration

@miki725
Copy link
Owner

miki725 commented Jul 15, 2015

@liquidpele which object? if that fixes the issue, do you mind opening a PR?

@markliederbach
Copy link

markliederbach commented Sep 12, 2016

Any updates on this issue?

django==1.9.9
DRF==3.2.4
DRF-bulk==0.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants