senaite / senaite.core

Enterprise Open Source Laboratory System (LIMS)
https://senaite.com
GNU General Public License v2.0
254 stars 145 forks source link

Fix type error for admitted sticker templates widget #2608

Closed ramonski closed 2 months ago

ramonski commented 2 months ago

Description of the issue/feature this PR addresses

This PR is complementary to https://github.com/senaite/senaite.core/pull/2584

The following traceback occurs, because the migrated sticker templates are set to [{}]:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 176, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 385, in publish_module
  Module ZPublisher.WSGIPublisher, line 288, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.autoform.view, line 42, in __call__
  Module plone.autoform.view, line 33, in render
  Module Products.Five.browser.pagetemplatefile, line 126, in __call__
  Module Products.Five.browser.pagetemplatefile, line 61, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 378, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 302, in render
  Module chameleon.template, line 192, in render
  Module f278745d4236cfe7df532e8a8d574e0e, line 517, in render
  Module 82b23ba6dc88305900870d9ad3b88696, line 1428, in render_master
  Module 82b23ba6dc88305900870d9ad3b88696, line 407, in render_content
  Module f278745d4236cfe7df532e8a8d574e0e, line 502, in __fill_content_core
  Module f278745d4236cfe7df532e8a8d574e0e, line 151, in render_content_core
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 225, in _eval
  Module Products.PageTemplates.Expressions, line 155, in render
  Module zope.browserpage.simpleviewclass, line 41, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 81, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 49, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 378, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 302, in render
  Module chameleon.template, line 192, in render
  Module dd38b593084195e8308561b531913cf3, line 898, in render
  Module dd38b593084195e8308561b531913cf3, line 725, in render_widget_wrapper
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 225, in _eval
  Module Products.PageTemplates.Expressions, line 155, in render
  Module z3c.form.widget, line 156, in render
  Module zope.browserpage.viewpagetemplatefile, line 49, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 378, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 302, in render
  Module chameleon.template, line 192, in render
  Module d32d361afd5650641dad4b6efc33a606, line 488, in render
  Module d32d361afd5650641dad4b6efc33a606, line 122, in render_widget_row
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 225, in _eval
  Module Products.PageTemplates.Expressions, line 155, in render
  Module collective.z3cform.datagridfield.datagridfield, line 324, in render
  Module z3c.form.object, line 310, in render
  Module z3c.form.widget, line 156, in render
  Module zope.browserpage.viewpagetemplatefile, line 49, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 378, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 302, in render
  Module chameleon.template, line 192, in render
  Module 4339159092d213fd06e7e144be3053fc, line 197, in render
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 225, in _eval
  Module Products.PageTemplates.Expressions, line 155, in render
  Module z3c.form.widget, line 156, in render
  Module zope.browserpage.viewpagetemplatefile, line 49, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 378, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 302, in render
  Module chameleon.template, line 215, in render
  Module chameleon.template, line 192, in render
  Module 788929a44b54c1d75e3e54ac3f6a0da7, line 348, in render
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 217, in _eval
  Module zope.tales.expressions, line 153, in _eval
  Module Products.PageTemplates.Expressions, line 134, in trustedBoboAwareZopeTraverse
  Module zope.traversing.adapters, line 156, in traversePathElement
   - __traceback_info__: (<SelectWidget 'form.widgets.admitted_sticker_templates.0.widgets.admitted'>, 'displayValue')
  Module zope.traversing.adapters, line 47, in traverse
   - __traceback_info__: (<SelectWidget 'form.widgets.admitted_sticker_templates.0.widgets.admitted'>, 'displayValue', [])
  Module z3c.form.widget, line 208, in displayValue
TypeError: 'NO_VALUE' object is not iterable

 - Expression: "view/displayValue"
 - Filename:   ... .form-3.7.1-py2.7.egg/z3c/form/browser/select_display.pt
 - Location:   (line 20: col 18)
 - Source:     repeat="value view/displayValue"
                             ^^^^^^^^^^^^^^^^^
 - Expression: "widget/render"
 - Filename:   ... ite/core/z3cform/widgets/datagrid/datagridrow_display.pt
 - Location:   (line 7: col 32)
 - Source:     ... div tal:replace="structure widget/render"></div>
                                              ^^^^^^^^^^^^^
 - Expression: "widget/render"
 - Filename:   ... enaite/core/z3cform/widgets/datagrid/datagrid_display.pt
 - Location:   (line 36: col 42)
 - Source:     ... div tal:replace="structure widget/render"></div>
                                              ^^^^^^^^^^^^^
 - Expression: "widget/render"
 - Filename:   ... e/src/senaite/core/browser/dexterity/templates/widget.pt
 - Location:   (line 63: col 34)
 - Source:     tal:replace="structure widget/render"
                                      ^^^^^^^^^^^^^
 - Expression: "widget/@@ploneform-render-widget"
 - Filename:   ... rc/senaite/core/browser/dexterity/templates/container.pt
 - Location:   (line 15: col 47)
 - Source:     ... place="structure widget/@@ploneform-render-widget"/>
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "provider:plone.abovecontentbody"
 - Filename:   ... te/core/browser/main_template/templates/main_template.pt
 - Location:   (line 132: col 84)
 - Source:     ... 
                                     ^
 - Expression: "context/@@main_template/macros/master"
 - Filename:   ... rc/senaite/core/browser/dexterity/templates/container.pt
 - Location:   (line 6: col 23)
 - Source:     ... tal:use-macro="context/@@main_template/macros/master"
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  repeat: <Products.PageTemplates.engine.RepeatDictWrapper object at 0x130d57f50>
               context: {}
               views: <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0x12d222810>
               modules: <zope.pagetemplate.engine.TraversableModuleImporter object at 0x102704410>
               args: ()
               attrs: {}
               nothing: None
               target_language: None
               default: <DEFAULT>
               request: <WSGIRequest, URL=http://localhost:8080/bikalims/setup/sampletypes/sampletype-9/view>
               loop: {}
               template: <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0x10a3a20d0>
               translate: <function translate at 0x122df95d0>
               options: {}
               view: <SelectWidget 'form.widgets.admitted_sticker_templates.0.widgets.admitted'>

Current behavior before PR

Some migrated instances raise a TypeError after migration, because the admitted sticker templates are set to [{}]

Desired behavior after PR is merged

Valid admitted sticker templates are set and the edit view is working properly.

-- I confirm I have tested this PR thoroughly and coded it according to PEP8 and Plone's Python styleguide standards.