Mezzanine 4.3.1 dict flatten issue during django context.flatten()

14 views
Skip to first unread message

saeed

unread,
Jul 1, 2019, 6:10:13 PM7/1/19
to Mezzanine Users
Additionally I've updated the underlying django like described here.
So I ended up with the following environment in short:
- Python 3.5
- Django 2.0.13
- Mezzanine 4.3.1

After some tests and some adaptions due to incompatibility between django and mezzanine, everything works fine, now, except one issue with comment:

Test steps:
After allowing a comment in blog post (admin), I write a comment, and after sending the comment I get:

ValueError at /blog/set-up-codesample-plugin-of-tinymce-for-mezzanine/

dictionary update sequence element #0 has length 3; 2 is required
Request Method:GET
Request URL:http://localhost:8000/blog/set-up-codesample-plugin-of-tinymce-for-mezzanine/
Django Version:2.0.13
Exception Type:ValueError
Exception Value:
dictionary update sequence element #0 has length 3; 2 is required
Exception Location:/Users/saeed/Development/django/venv_unitecinfo/lib/python3.5/site-packages/django/template/context.py in flatten, line 123
Python Executable:/Users/saeed/Development/django/venv_unitecinfo/bin/python
Python Version:3.5.2
Python Path:
['/Users/saeed/Development/django/unitecinfo',
 '/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
 '/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
 '/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
 '/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
 '/Users/saeed/Development/django/venv_unitecinfo/lib/python3.5/site-packages']
Server time:Sun, 30 Jun 2019 17:36:42 +0200

Error during template rendering

In template /Users/saeed/Development/django/unitecinfo/theme/templates/generic/includes/comment.html, error at line 73

dictionary update sequence element #0 has length 3; 2 is required

63 {# Uncomment for debugging only. #}
64 <p> My id: {{ comment.id }}, I replied to: {{comment.replied_to_id}}</p>
65 <p> Do I have children? {% if comment.id in all_comments|defaultdict_keys %} yes {% else %} no {% endif %} </p>
66 <p> What is my level in the tree?: {{ comment|comment_level }}</p>
67 {% endcomment %}
68
69 <div class="comment-border clearfix">
70
71 {% if settings.COMMENTS_USE_RATINGS %}
72 <div class="rating">
73 {% rating_for comment %}
74 </div>
75 {% endif %}

The problem occurs when mezzanine uses flatten function of django context.py

  • /Users/saeed/Development/django/venv_unitecinfo/lib/python3.5/site-packages/mezzanine/generic/templatetags/rating_tags.py in rating_for
    1. ...
    VariableValue
    context
    [{'True': True, 'None': None, 'False': False}, [{'True': True, 'None': None, 'False': False}, {'has_home': True, 'menu_pages': defaultdict(<class 'list'>, {8: [<Page: Portfolios / Software Development>, <Page: Portfolios / Test Automation>, <Page: Portfolios / IT Consulting>], 9: [<Page: Portfolios / Software Development / Microservices>, <Page: Portfolios / Software Development / Web Crawler>, <Page: Portfolios / Software Development / Web Apps>, <Page: Portfolios / Software Development / PDF parser>, <Page: Portfolios / Software Development / Big Data + ETL>], None: [<Page: Home>, <Page: Blog>, <Page: Features>, <Page: Portfolios>, <Page: Testimonials>, <Page: Contact us>, <Page: Pages>], 11: [<Page: Portfolios / IT Consulting / Test Management>, <Page: Portfolios / IT Consulting / Test Process Improvement>], 10: [<Page: Portfolios / Test Automation / Qt C++ GUI>, <Page: Portfolios / Test Automation / Java Client Server GUI>, <Page: Portfolios / Test Automation / Web Apps>], 14: [<Page: Example pages / About us>, <Page: Pages / Resume>]}), 'False': False, 'STATIC_URL': '/static/', 'settings': {'COMMENTS_DISQUS_SHORTNAME': '', 'PERSONAL_PHONE': '+49 69-967-516-00', 'SOCIAL_LINK_TUMBLR': 'https://tumblr.com/test', 'DEV_SERVER': True, 'COMMENTS_DISQUS_API_PUBLIC_KEY': '', 'SITE_TITLE': 'unitec informatics', 'JQUERY_UI_FILENAME': 'jquery-ui-1.8.24.min.js', 'PERSONAL_EMAIL': 'You want to write us?', 'SITE_TAGLINE': 'You are a serious company. You deserve a serious solution.', 'FORMS_USE_HTML5': False, 'BLOG_USE_FEATURED_IMAGE': True, 'COMMENTS_USE_RATINGS': True, 'ADMIN_MENU_COLLAPSED': False, 'SOCIAL_LINK_VIMEO': 'https://vimeo.com/test', 'SOCIAL_LINK_FACEBOOK': 'https://facebook.com/test', 'COMMENTS_ORDERBYSCORE': True, 'COMMENTS_NUM_LATEST': 5, 'COLORSCHEME': 'scheme-orange', 'COMMENTS_PER_PAGE': 10, 'PERSONAL_SKYPE': 'shiraznet1', 'GOOGLE_ANALYTICS_ID': '', 'USE_MODELTRANSLATION': False, 'JQUERY_FILENAME': 'jquery-1.8.3.min.js', 'SOCIAL_LINK_TWITTER': 'https://twitter.com/ShirazNet', 'USE_L10N': False, 'PERSONAL_NAME': 'unitec informatics gmbh', 'BITLY_ACCESS_TOKEN': '', 'MEZZANINE_ADMIN_PREFIX': 'grappelli/', 'GRAPPELLI_INSTALLED': True, 'SOCIAL_LINK_DELICIOUS': 'https://delicious.com/test', 'COMMENTS_DISQUS_API_SECRET_KEY': '', 'PERSONAL_ADDRESS': 'Mergenthalerallee 10-12, 65760 Eschborn', 'LOGIN_URL': '/accounts/login/'}, 'object_for_comments': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'request': <WSGIRequest: GET '/blog/set-up-codesample-plugin-of-tinymce-for-mezzanine/'>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x11173f208>, 'editable_obj': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'block': <Block Node: blog_post_detail_comments. Contents: [<TextNode: '\n    '>, <IfNode>, <TextNode: '\n    '>]>, 'unposted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'page': <Page: Blog>, 'LANGUAGE_BIDI': False, 'tags': [], 'comment_url': '/comment/', 'on_home': False, 'user': <SimpleLazyObject: <User: admin>>, 'True': True, 'blog_post': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'posted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'csrf_token': <SimpleLazyObject: 'y9HXCgdB1UY1oYCz8fqPzIs9Z5tfr1bfBuedwLL0DxzDYjHf4kD28r6RYnfSoqoM'>, 'all_comments': defaultdict(<class 'list'>, {None: [<ThreadedComment: testuser: fewreqwr jwröqwjr woqjrowq rüqwr...>]}), 'None': None, 'MEDIA_URL': '/media/', '_parent_page_ids': {1: None, 2: None, 6: 14, 7: 14, 8: None, 9: 8, 10: 8, 11: 8, 14: None, 15: None, 16: None, 17: None, 18: 9, 19: 9, 21: 11, 22: 11, 23: 10, 24: 10, 35: 10, 45: 9, 46: 9, 47: 9}, 'messages': <django.contrib.messages.storage.cookie.CookieStorage object at 0x1116d84a8>, '_current_page': <Page: Blog>, 'LANGUAGES': (('en', 'English'),), 'TIME_ZONE': 'Europe/Berlin', 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'SUCCESS': 25, 'WARNING'... <trimmed 4573 bytes string>
    f
    'sum'
    obj
    <ThreadedComment: testuser: fewreqwr jwröqwjr woqjrowq rüqwr...>
    rating_name
    'rating'
    rating_string
    'generic.threadedcomment.32'
    ratings
    ''

  • /Users/saeed/Development/django/venv_unitecinfo/lib/python3.5/site-packages/django/template/context.py in flatten
    1. ...
    VariableValue
    d
    [{'True': True, 'None': None, 'False': False}, {'has_home': True, 'menu_pages': defaultdict(<class 'list'>, {8: [<Page: Portfolios / Software Development>, <Page: Portfolios / Test Automation>, <Page: Portfolios / IT Consulting>], 9: [<Page: Portfolios / Software Development / Microservices>, <Page: Portfolios / Software Development / Web Crawler>, <Page: Portfolios / Software Development / Web Apps>, <Page: Portfolios / Software Development / PDF parser>, <Page: Portfolios / Software Development / Big Data + ETL>], None: [<Page: Home>, <Page: Blog>, <Page: Features>, <Page: Portfolios>, <Page: Testimonials>, <Page: Contact us>, <Page: Pages>], 11: [<Page: Portfolios / IT Consulting / Test Management>, <Page: Portfolios / IT Consulting / Test Process Improvement>], 10: [<Page: Portfolios / Test Automation / Qt C++ GUI>, <Page: Portfolios / Test Automation / Java Client Server GUI>, <Page: Portfolios / Test Automation / Web Apps>], 14: [<Page: Example pages / About us>, <Page: Pages / Resume>]}), 'False': False, 'STATIC_URL': '/static/', 'settings': {'COMMENTS_DISQUS_SHORTNAME': '', 'PERSONAL_PHONE': '+49 69-967-516-00', 'SOCIAL_LINK_TUMBLR': 'https://tumblr.com/test', 'DEV_SERVER': True, 'COMMENTS_DISQUS_API_PUBLIC_KEY': '', 'SITE_TITLE': 'unitec informatics', 'JQUERY_UI_FILENAME': 'jquery-ui-1.8.24.min.js', 'PERSONAL_EMAIL': 'You want to write us?', 'SITE_TAGLINE': 'You are a serious company. You deserve a serious solution.', 'FORMS_USE_HTML5': False, 'BLOG_USE_FEATURED_IMAGE': True, 'COMMENTS_USE_RATINGS': True, 'ADMIN_MENU_COLLAPSED': False, 'SOCIAL_LINK_VIMEO': 'https://vimeo.com/test', 'SOCIAL_LINK_FACEBOOK': 'https://facebook.com/test', 'COMMENTS_ORDERBYSCORE': True, 'COMMENTS_NUM_LATEST': 5, 'COLORSCHEME': 'scheme-orange', 'COMMENTS_PER_PAGE': 10, 'PERSONAL_SKYPE': 'shiraznet1', 'GOOGLE_ANALYTICS_ID': '', 'USE_MODELTRANSLATION': False, 'JQUERY_FILENAME': 'jquery-1.8.3.min.js', 'SOCIAL_LINK_TWITTER': 'https://twitter.com/ShirazNet', 'USE_L10N': False, 'PERSONAL_NAME': 'unitec informatics gmbh', 'BITLY_ACCESS_TOKEN': '', 'MEZZANINE_ADMIN_PREFIX': 'grappelli/', 'GRAPPELLI_INSTALLED': True, 'SOCIAL_LINK_DELICIOUS': 'https://delicious.com/test', 'COMMENTS_DISQUS_API_SECRET_KEY': '', 'PERSONAL_ADDRESS': 'Mergenthalerallee 10-12, 65760 Eschborn', 'LOGIN_URL': '/accounts/login/'}, 'object_for_comments': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'request': <WSGIRequest: GET '/blog/set-up-codesample-plugin-of-tinymce-for-mezzanine/'>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x11173f208>, 'editable_obj': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'block': <Block Node: blog_post_detail_comments. Contents: [<TextNode: '\n    '>, <IfNode>, <TextNode: '\n    '>]>, 'unposted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'page': <Page: Blog>, 'LANGUAGE_BIDI': False, 'tags': [], 'comment_url': '/comment/', 'on_home': False, 'user': <SimpleLazyObject: <User: admin>>, 'True': True, 'blog_post': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'posted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'csrf_token': <SimpleLazyObject: 'y9HXCgdB1UY1oYCz8fqPzIs9Z5tfr1bfBuedwLL0DxzDYjHf4kD28r6RYnfSoqoM'>, 'all_comments': defaultdict(<class 'list'>, {None: [<ThreadedComment: testuser: fewreqwr jwröqwjr woqjrowq rüqwr...>]}), 'None': None, 'MEDIA_URL': '/media/', '_parent_page_ids': {1: None, 2: None, 6: 14, 7: 14, 8: None, 9: 8, 10: 8, 11: 8, 14: None, 15: None, 16: None, 17: None, 18: 9, 19: 9, 21: 11, 22: 11, 23: 10, 24: 10, 35: 10, 45: 9, 46: 9, 47: 9}, 'messages': <django.contrib.messages.storage.cookie.CookieStorage object at 0x1116d84a8>, '_current_page': <Page: Blog>, 'LANGUAGES': (('en', 'English'),), 'TIME_ZONE': 'Europe/Berlin', 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40, 'INFO': 20}, 'LANGUAGE_CODE'... <trimmed 4525 bytes string>
    flat
    {'False': False, 'None': None, 'True': True}
    self
    [{'True': True, 'None': None, 'False': False}, [{'True': True, 'None': None, 'False': False}, {'has_home': True, 'menu_pages': defaultdict(<class 'list'>, {8: [<Page: Portfolios / Software Development>, <Page: Portfolios / Test Automation>, <Page: Portfolios / IT Consulting>], 9: [<Page: Portfolios / Software Development / Microservices>, <Page: Portfolios / Software Development / Web Crawler>, <Page: Portfolios / Software Development / Web Apps>, <Page: Portfolios / Software Development / PDF parser>, <Page: Portfolios / Software Development / Big Data + ETL>], None: [<Page: Home>, <Page: Blog>, <Page: Features>, <Page: Portfolios>, <Page: Testimonials>, <Page: Contact us>, <Page: Pages>], 11: [<Page: Portfolios / IT Consulting / Test Management>, <Page: Portfolios / IT Consulting / Test Process Improvement>], 10: [<Page: Portfolios / Test Automation / Qt C++ GUI>, <Page: Portfolios / Test Automation / Java Client Server GUI>, <Page: Portfolios / Test Automation / Web Apps>], 14: [<Page: Example pages / About us>, <Page: Pages / Resume>]}), 'False': False, 'STATIC_URL': '/static/', 'settings': {'COMMENTS_DISQUS_SHORTNAME': '', 'PERSONAL_PHONE': '+49 69-967-516-00', 'SOCIAL_LINK_TUMBLR': 'https://tumblr.com/test', 'DEV_SERVER': True, 'COMMENTS_DISQUS_API_PUBLIC_KEY': '', 'SITE_TITLE': 'unitec informatics', 'JQUERY_UI_FILENAME': 'jquery-ui-1.8.24.min.js', 'PERSONAL_EMAIL': 'You want to write us?', 'SITE_TAGLINE': 'You are a serious company. You deserve a serious solution.', 'FORMS_USE_HTML5': False, 'BLOG_USE_FEATURED_IMAGE': True, 'COMMENTS_USE_RATINGS': True, 'ADMIN_MENU_COLLAPSED': False, 'SOCIAL_LINK_VIMEO': 'https://vimeo.com/test', 'SOCIAL_LINK_FACEBOOK': 'https://facebook.com/test', 'COMMENTS_ORDERBYSCORE': True, 'COMMENTS_NUM_LATEST': 5, 'COLORSCHEME': 'scheme-orange', 'COMMENTS_PER_PAGE': 10, 'PERSONAL_SKYPE': 'shiraznet1', 'GOOGLE_ANALYTICS_ID': '', 'USE_MODELTRANSLATION': False, 'JQUERY_FILENAME': 'jquery-1.8.3.min.js', 'SOCIAL_LINK_TWITTER': 'https://twitter.com/ShirazNet', 'USE_L10N': False, 'PERSONAL_NAME': 'unitec informatics gmbh', 'BITLY_ACCESS_TOKEN': '', 'MEZZANINE_ADMIN_PREFIX': 'grappelli/', 'GRAPPELLI_INSTALLED': True, 'SOCIAL_LINK_DELICIOUS': 'https://delicious.com/test', 'COMMENTS_DISQUS_API_SECRET_KEY': '', 'PERSONAL_ADDRESS': 'Mergenthalerallee 10-12, 65760 Eschborn', 'LOGIN_URL': '/accounts/login/'}, 'object_for_comments': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'request': <WSGIRequest: GET '/blog/set-up-codesample-plugin-of-tinymce-for-mezzanine/'>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x11173f208>, 'editable_obj': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'block': <Block Node: blog_post_detail_comments. Contents: [<TextNode: '\n    '>, <IfNode>, <TextNode: '\n    '>]>, 'unposted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'page': <Page: Blog>, 'LANGUAGE_BIDI': False, 'tags': [], 'comment_url': '/comment/', 'on_home': False, 'user': <SimpleLazyObject: <User: admin>>, 'True': True, 'blog_post': <BlogPost: Set up codesample plugin of TinyMCE for mezzanine>, 'posted_comment_form': <ThreadedCommentForm bound=False, valid=Unknown, fields=(content_type;object_pk;timestamp;security_hash;name;email;url;comment;honeypot)>, 'csrf_token': <SimpleLazyObject: 'y9HXCgdB1UY1oYCz8fqPzIs9Z5tfr1bfBuedwLL0DxzDYjHf4kD28r6RYnfSoqoM'>, 'all_comments': defaultdict(<class 'list'>, {None: [<ThreadedComment: testuser: fewreqwr jwröqwjr woqjrowq rüqwr...>]}), 'None': None, 'MEDIA_URL': '/media/', '_parent_page_ids': {1: None, 2: None, 6: 14, 7: 14, 8: None, 9: 8, 10: 8, 11: 8, 14: None, 15: None, 16: None, 17: None, 18: 9, 19: 9, 21: 11, 22: 11, 23: 10, 24: 10, 35: 10, 45: 9, 46: 9, 47: 9}, 'messages': <django.contrib.messages.storage.cookie.CookieStorage object at 0x1116d84a8>, '_current_page': <Page: Blog>, 'LANGUAGES': (('en', 'English'),), 'TIME_ZONE': 'Europe/Berlin', 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'SUCCESS': 25, 'WARNING'... <trimmed 4573 bytes string>
 It's happening when a template uses an inclusion_tag type template tag „render_for“ that returns its context argument.
See similar problem reported here: https://code.djangoproject.com/ticket/24765 

Any idea how to fix this?

Regards,
Saeed
Reply all
Reply to author
Forward
0 new messages