MultiValueDictKeyError at /dashboard/catalogue/products/90/ "u'stockrecords-0-id'"

490 views
Skip to first unread message

Chris L

unread,
Apr 25, 2014, 3:34:59 PM4/25/14
to django...@googlegroups.com
In my application, I create a required stockrecord for each partner a user is associated with.

I have excluded the partner field from stock records, and I set it myself manually inside dashboard/catalgoue/views.py process_all_forms() which looks like this:

        stockrecord_formset = self.stockrecord_formset(
            self.product_class, self.request.user,
            self.request.POST, instance=self.object)

        i = 0
        for form in stockrecord_formset:
            stockrecord = form.save(commit=False)
            stockrecord.partner = stockrecord_formset.get_warehouse(i)
            stockrecord.save()
            i += 1

This works fine when creating a new product, however, if I edit a product, change nothing, then hit 'Save' I get this MultiValueDictKeyError. I am not sure what exactly is going on here, so any help would be appreciated.

Traceback:
Environment:


Request Method: POST

Django Version: 1.6.1
Python Version: 2.7.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.admin',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.flatpages',
 'django.contrib.staticfiles',
 'oscar.apps.dashboard.pages',
 'oscar.apps.dashboard.reviews',
 'south',
 'compressor',
 'oscar',
 'oscar.apps.analytics',
 'oscar.apps.checkout',
 'oscar.apps.address',
 'oscar.apps.shipping',
 'catalogue',
 'oscar.apps.catalogue.reviews',
 'partner',
 'oscar.apps.basket',
 'oscar.apps.payment',
 'oscar.apps.offer',
 'oscar.apps.order',
 'customer',
 'oscar.apps.promotions',
 'oscar.apps.search',
 'oscar.apps.voucher',
 'oscar.apps.wishlists',
 'dashboard',
 'oscar.apps.dashboard.reports',
 'oscar.apps.dashboard.users',
 'oscar.apps.dashboard.orders',
 'oscar.apps.dashboard.promotions',
 'dashboard.catalogue',
 'oscar.apps.dashboard.offers',
 'dashboard.partners',
 'oscar.apps.dashboard.pages',
 'oscar.apps.dashboard.ranges',
 'oscar.apps.dashboard.reviews',
 'oscar.apps.dashboard.vouchers',
 'oscar.apps.dashboard.communications',
 'haystack',
 'treebeard',
 'sorl.thumbnail']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'oscar.apps.basket.middleware.BasketMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
  228.         return super(BaseUpdateView, self).post(request, *args, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
  171.             return self.form_valid(form)
File "/home/suprafly/TradeWinds_project/TradeWinds/dashboard/catalogue/views.py" in form_valid
  240.         return self.process_all_forms(form)
File "/home/suprafly/TradeWinds_project/TradeWinds/dashboard/catalogue/views.py" in process_all_forms
  259.         self.add_warehouse_to_forms(stockrecord_formset)
File "/home/suprafly/TradeWinds_project/TradeWinds/dashboard/catalogue/views.py" in add_warehouse_to_forms
  293.         for form in stockrecord_formset:
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/forms/formsets.py" in __iter__
  65.         return iter(self.forms)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/utils/functional.py" in __get__
  49.         res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/forms/formsets.py" in forms
  133.         forms = [self._construct_form(i) for i in xrange(self.total_form_count())]
File "/home/suprafly/TradeWinds_project/TradeWinds/dashboard/catalogue/forms.py" in _construct_form
  151.                 i, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  848.         form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  564.             pk = self.data[pk_key]
File "/home/suprafly/Envs/TradeWinds/local/lib/python2.7/site-packages/django/utils/datastructures.py" in __getitem__
  301.             raise MultiValueDictKeyError(repr(key))

Exception Type: MultiValueDictKeyError at /dashboard/catalogue/products/90/
Exception Value: "u'stockrecords-0-id'"

Maik Hoepfel

unread,
Apr 27, 2014, 8:37:45 AM4/27/14
to django...@googlegroups.com
Hi Chris,

MultiValueDictKeyError is just the exception a MultiValueDict throws
where are normal dict would throw a regular KeyError. So
'stockrecords-0-id' is missing from the POST data. I think that's a
hidden field Django formsets normally render out. I'd presume the issue
is rooted in your customisations somewhere.

Regards,

Maik
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/0582b8fa-f765-4dd4-87fa-2b2d2e266379%40googlegroups.com
> <https://groups.google.com/d/msgid/django-oscar/0582b8fa-f765-4dd4-87fa-2b2d2e266379%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Chris L

unread,
Apr 29, 2014, 6:36:33 PM4/29/14
to django...@googlegroups.com
Thanks for the insight Maik. I suppose it is from my customizations, too, but it's unclear how.


Which is interesting, because that's the exact problem I am experiencing, but from the dashboard and not the admin.

Chris L

unread,
Jun 6, 2014, 6:15:44 PM6/6/14
to django...@googlegroups.com
Finally figured this one out!

The problem was in the product_update.html template, I had removed the line:
                                                {% include "partials/form_field.html" with field=stockrecord_form.id nolabel=True %}

But, this is apparently essential to the POST data.

On Sunday, April 27, 2014 5:37:45 AM UTC-7, Maik Hoepfel wrote:
Reply all
Reply to author
Forward
0 new messages