ValueError: too many values to unpack when accessing entry via admin
See original GitHub issueActual behavior
I created one entry in the admin and when i tried to change it i couldn’t anymore. I can view the entry as a user on the page, but i can not create new entries nor edit the created. see below the traceback (form which I can’t get any useful information what happend):
Expected behavior
Just tryng to change the created entry or creating a new one in the admin.
Steps to reproduce the issue
No idea what happend. I created one entry and tried to change it. Don’t understand this.
Specifications
- Zinnia version: 0.18.1
- Django version: 1.11.2
- Python version: 2.7
- Operating system: Ubuntu
Disclaimer
Please read these questions carefully and answer honestly with an x
into all the boxes [ ]
:
- I have read the guidelines for contributing linked to above.
- I have checked for duplicate issues.
- This is not a support request.
File “/usr/lib/python2.7/wsgiref/handlers.py”, line 85, in run self.result = application(self.environ, self.start_response) File “/home/ubuntu/workspace/project/apps/django/contrib/staticfiles/handlers.py”, line 63, in call return self.application(environ, start_response) File “/home/ubuntu/workspace/project/apps/django/core/handlers/wsgi.py”, line 157, in call response = self.get_response(request) File “/home/ubuntu/workspace/project/apps/django/core/handlers/base.py”, line 124, in get_response response = self._middleware_chain(request) File “/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py”, line 43, in inner response = response_for_exception(request, exc) File “/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py”, line 93, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File “/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py”, line 41, in inner response = get_response(request) File “/home/ubuntu/workspace/project/apps/django/core/handlers/base.py”, line 249, in _legacy_get_response response = self._get_response(request) File “/home/ubuntu/workspace/project/apps/django/core/handlers/base.py”, line 217, in _get_response response = self.process_exception_by_middleware(e, request) File “/home/ubuntu/workspace/project/apps/django/core/handlers/base.py”, line 215, in _get_response response = response.render() File “/home/ubuntu/workspace/project/apps/django/template/response.py”, line 107, in render self.content = self.rendered_content File “/home/ubuntu/workspace/project/apps/django/template/response.py”, line 84, in rendered_content content = template.render(context, self._request) File “/home/ubuntu/workspace/project/apps/django/template/backends/django.py”, line 66, in render return self.template.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 207, in render return self._render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 199, in _render return self.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/loader_tags.py”, line 177, in render return compiled_parent._render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 199, in _render return self.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/loader_tags.py”, line 177, in render return compiled_parent._render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 199, in _render return self.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/loader_tags.py”, line 72, in render result = block.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/loader_tags.py”, line 72, in render result = block.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/defaulttags.py”, line 216, in render nodelist.append(node.render_annotated(context)) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/loader_tags.py”, line 216, in render return template.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 209, in render return self._render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 199, in _render return self.nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/defaulttags.py”, line 216, in render nodelist.append(node.render_annotated(context)) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/defaulttags.py”, line 216, in render nodelist.append(node.render_annotated(context)) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/defaulttags.py”, line 322, in render return nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/defaulttags.py”, line 322, in render return nodelist.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 990, in render bit = node.render_annotated(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 957, in render_annotated return self.render(context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 1046, in render return render_value_in_context(output, context) File “/home/ubuntu/workspace/project/apps/django/template/base.py”, line 1024, in render_value_in_context value = force_text(value) File “/home/ubuntu/workspace/project/apps/django/utils/encoding.py”, line 78, in force_text s = six.text_type(s) File “/home/ubuntu/workspace/project/apps/django/utils/html.py”, line 376, in <lambda> klass.unicode = lambda self: mark_safe(klass_unicode(self)) File “/home/ubuntu/workspace/project/apps/django/forms/boundfield.py”, line 41, in str return self.as_widget() File “/home/ubuntu/workspace/project/apps/django/forms/boundfield.py”, line 127, in as_widget **kwargs File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 220, in render context = self.get_context(name, value, attrs) File “/home/ubuntu/workspace/project/apps/django/contrib/admin/widgets.py”, line 281, in get_context ‘rendered_widget’: self.widget.render(name, value, attrs), File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 220, in render context = self.get_context(name, value, attrs) File “/home/ubuntu/workspace/project/apps/django/contrib/admin/widgets.py”, line 38, in get_context context = super(FilteredSelectMultiple, self).get_context(name, value, attrs) File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 667, in get_context context = super(Select, self).get_context(name, value, attrs) File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 629, in get_context context[‘widget’][‘optgroups’] = self.optgroups(name, context[‘widget’][‘value’], attrs) File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 577, in optgroups for index, (option_value, option_label) in enumerate(chain(self.choices)): ValueError: too many values to unpack
Also I found the forms modules in django that started to throw this error and placed a print in it, here is what I got:
def optgroups(self, name, value, attrs=None):
"""Return a list of optgroups for this widget."""
groups = []
has_selected = False
print "name",name
print "value",value
print "attrs",attrs
print self.choices
for index, (option_value, option_label) in enumerate(chain(self.choices)):
if option_value is None:
option_value = ''
subgroup = []
if isinstance(option_label, (list, tuple)):
group_name = option_value
subindex = 0
choices = option_label
else:
group_name = None
subindex = None
choices = [(option_value, option_label)]
groups.append((group_name, subgroup, index))
for subvalue, sublabel in choices:
selected = (
force_text(subvalue) in value and
(has_selected is False or self.allow_multiple_selected)
)
if selected is True and has_selected is False:
has_selected = True
subgroup.append(self.create_option(
name, subvalue, sublabel, selected, index,
subindex=subindex, attrs=attrs,
))
if subindex is not None:
subindex += 1
return groups
value [u’0’] attrs {u’id’: u’id_status’} [(0, u’draft’), (1, u’hidden’), (2, u’published’)] name sites value [u’2’] attrs {u’required’: True, u’id’: u’id_sites’} <django.forms.models.ModelChoiceIterator object at 0x7f0980bf5450> name content_template value [u’zinnia/_entry_detail.html’] attrs {u’required’: True, u’id’: u’id_content_template’} [(‘zinnia/_entry_detail.html’, u’Default template’)] name detail_template value [u’entry_detail.html’] attrs {u’required’: True, u’id’: u’id_detail_template’} [(‘entry_detail.html’, u’Default template’)] name authors value [u’66’] attrs {u’id’: u’id_authors’} <django.forms.models.ModelChoiceIterator object at 0x7f0980bf5f10> name related value [u’‘] attrs {u’id’: u’id_related’} <django.forms.models.ModelChoiceIterator object at 0x7f0980b7d150> name categories value [u’‘] attrs {u’id’: u’id_categories’} <zinnia.admin.fields.MPTTModelChoiceIterator object at 0x7f0980b7d310> Traceback (most recent call last): and here comes the error traceback
EDIT: I reinstalled the whole package and the issue persists …
EDIT2: Another couple of trys in File “/home/ubuntu/workspace/project/apps/django/forms/widgets.py”, line 577, in optgroups, iadded this to see values:
def optgroups(self, name, value, attrs=None):
"""Return a list of optgroups for this widget."""
groups = []
has_selected = False
print name
print value
print attrs
try:
print enumerate(chain(self.choices))
except:
print enumerate(chain(self.choices.items()))
for item in enumerate(chain(self.choices)):
print item
for index, (option_value, option_label) in enumerate(chain(self.choices)):
And these are the results:
related [] {u’id’: u’id_related’} <enumerate object at 0x7f32eea2adc0> (0, (2, u’fff: published’)) categories [] {u’id’: u’id_categories’} <enumerate object at 0x7f32eea2ad70> (0, (1, u’Test123’, (1, 1)))
Obviously it breaks beacuse of categories. My category Test123 does for some reason arrive with four values instead of the expected three. Once I deleted the category everything started to workout fine. I still consider this a zinnia bug. I currently can not use Categories because they break the entry admin.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12
Top GitHub Comments
The problem appears to be how Django 1.11 receives the value of the
MPTTModelMultipleChoiceField
choices that returns a tuple of left and right sort values to implement MPTT in addition to the choice and its label (that is the extra(1,1)
returned when stefko18 enumerated the values ofid_categories
).If you comment out the following lines 56-60 in zinnia/admin/forms.py, the admin interface works (albeit without MPTT), i.e.:
Unfortunately, I don’t know enough about the implementation of either this widget to fix the problem.
For me, I have identified the problem code as being in method choice() of class MPTTModelChoiceIterator within the module zinnia/admin/fields.py.
The zinnia code overloads the choice method of ModelChoiceIterator from django.forms.models. Unfortunately this overload returns a tuple that django chokes on.
Specifically, this next line seems wrong:
return super(MPTTModelChoiceIterator, self).choice(obj) + ((tree_id, left),)
A short term fix would be to remove this overload entirely or just change the code to return the super without the tree and left parameters:
return super(MPTTModelChoiceIterator, self).choice(obj)
This change would leave the mptt nested categories in place unlike the previous solution above. The only downside is that the method docs refer to ‘future sorting’ of the tree and the above change would remove that future functionality. Hope this helps someone.