DRF Serializer throws KeyError

1,274 views
Skip to first unread message

Ajit Gauli

unread,
Oct 23, 2014, 4:52:19 PM10/23/14
to django-res...@googlegroups.com
Hey guys,

         I'm working on a  django project that I started as a branch of an existing one. The person working on the master branch made some changes on my app models, and migrated those changes to the db which I'm using as well. I updated those models and serializers on my project, but my api is choking on those newly added fields giving me KeyError. Here's the stack trace.

KeyError at /api/stampede/jobs/

'flops'
Request Method: GET
Request URL: http://129.114.7.126:8000/api/stampede/jobs/?user=madhavg
Django Version: 1.6.5
Exception Type: KeyError
Exception Value: 'flops'

Exception Location: /usr/lib/python2.7/site-packages/rest_framework/serializers.py in get_fields, line 246
Python Executable: /bin/python
Python Version: 2.7.5
Python Path: ['/home/agauli/tacc_stats/tacc_stats/site',
 
'/home/rodeo/tacc_stats',
 
'/usr/lib64/python27.zip',
 
'/usr/lib64/python2.7',
 
'/usr/lib64/python2.7/plat-linux2',
 
'/usr/lib64/python2.7/lib-tk',
 
'/usr/lib64/python2.7/lib-old',
 
'/usr/lib64/python2.7/lib-dynload',
 
'/root/.local/lib/python2.7/site-packages',
 
'/usr/lib64/python2.7/site-packages',
 
'/usr/lib64/python2.7/site-packages/gtk-2.0',
 
'/usr/lib/python2.7/site-packages',
 
'/home/agauli/tacc_stats/tacc_stats/site/tacc_stats_site',
 
'/home/agauli/tacc_stats/tacc_stats/site/tacc_stats_site/../']


Please share your ideas if you have come across similar situation. Thanks in advance. 

Ajit Gauli

Xavier Ordoquy

unread,
Oct 23, 2014, 4:55:57 PM10/23/14
to django-res...@googlegroups.com
Hi,

You need to check you serializer fields listed still exist on the model.

Regards,
Xavier Ordoquy,
Linovia.


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ajit Gauli

unread,
Oct 23, 2014, 5:07:21 PM10/23/14
to django-res...@googlegroups.com
Xavier,
              Thanks for the reply. My model is updated, and it has all the fields that I mention in the serializer. What else could be the reason?

Ajit 

Xavier Ordoquy

unread,
Oct 25, 2014, 6:17:22 PM10/25/14
to django-res...@googlegroups.com
At this point I think a detailed stack trace as well as the model and serializer code would be required to help further.

Regards,
Xavier Ordoquy,
Linovia.

Liao Feng

unread,
Oct 25, 2014, 10:02:41 PM10/25/14
to django-res...@googlegroups.com
assume we get a serializer named UserSerializer,
we can check the fields declared in UserSerializer this way:

serializer=UserSerializer()
serializer
.get_fields()

check whether `flops` in the returned dictionary.



在 2014年10月24日星期五UTC+8上午4时52分19秒,Ajit Gauli写道:
Reply all
Reply to author
Forward
0 new messages