Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate name: value #99

Open
NicolasGoeddel opened this issue Oct 21, 2020 · 2 comments
Open

Duplicate name: value #99

NicolasGoeddel opened this issue Oct 21, 2020 · 2 comments

Comments

@NicolasGoeddel
Copy link

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

I created a new control panel, derived from plone.supermodel.model.Schema and then used together with a plone.app.registry.browser.controlpanel.RegistryEditForm and the plone.app.registry.browser.controlpanel.ControlPanelWrapper.

class IControlPanel(model.Schema):

    site_color = field.TextLine(
        title=_('page_color', default='Farbe der Seite'),
        description=_('page_color_desc', default='Geben Sie die Farbe der Seite an.'),
        required=False
    )

    site_email = field.TextLine(
        title='E-Mail der Website',
        description='E-Mails der Website werden an diese E-Mail gesendet.',
        required=False
    )

What happened:

After a reinstall of my addon I always get this error:

raise ValueError("Duplicate name", name)

Or to be exact:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 359, in publish_module
  Module ZPublisher.WSGIPublisher, line 254, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.z3cform.layout, line 63, in __call__
  Module plone.z3cform.layout, line 47, in update
  Module plone.z3cform.fieldsets.extensible, line 64, in update
  Module plone.autoform.form, line 34, in updateFields
  Module plone.autoform.base, line 68, in updateFieldsFromSchemata
  Module plone.autoform.utils, line 279, in processFields
  Module z3c.form.field, line 137, in __init__
ValueError: ('Duplicate name', 'value')

It reminds a lot of this one: plone/plone.behavior#14

What I think

In line 130 of the same file the field (plone.registry.field.TextLine) of my schema gets wrapped inside a newly created Field instance. Then in the next line the name will be derived from it. But this name always seems to be "value" instead of the real field name.
If I run the debugger before the exception I can see this:

# field <=> site_email
# self._data['value'] <=> site_color
(Pdb) field.title
'E-Mail der Website'
(Pdb) self._data
{'value': <Field 'value'>}
(Pdb) self._data['value']
<Field 'value'>
(Pdb) self._data['value'].field
<plone.registry.field.TextLine object at 0x7f4725e8c0b0 oid 0x17b2f in <Connection at 7f4739e34dc0>>
(Pdb) self._data['value'].field.title
'page_color'
(Pdb) self._data['value'].field.__name__
'value'
(Pdb) self._data['value'].__name__
'value'
(Pdb) field.__name__
'value'

So it seems that the original field also has the name "value" which is weird. Of course it should be site_color and site_email.

Should name not remain untouched?

What version of Python and Zope/Addons I am using:

Python 3.8.2
Zope 4.5.1
Plone 5.2.2

@d-maurer
Copy link
Contributor

d-maurer commented Oct 21, 2020 via email

@NicolasGoeddel
Copy link
Author

I also fiddled a bit around and found out that the issue was that I used plone.registry.field.TextLine instead of zope.schema.TextLine. So maybe this is not an issue anymore but the exception was just not that helpful to me.

On the other hand I also have a field like this:

    resourceOrder = zope.schema.List(
        title=_("resource_order", default="Resource Order"),
        description=_("resource_order_desc", default="..."),
        required=False,
        value_type=plone.registry.field.Choice(
            vocabulary=registeredResourcesStatic
        )
    )

Here it seems essential to use plone.registry.field.Choice as value_type because else the form can not be rendered. However I found that out by try and error because the documentation is not that great.

I guess this issue can be closed then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants