zopefoundation / zope.configuration

Extensible system for supporting various kinds of configurations
https://zopeconfiguration.readthedocs.io
Other
1 stars 6 forks source link

Regression in 4.2: PythonIdentifier fromUnicode no longer allows empty strings #36

Closed jamadden closed 6 years ago

jamadden commented 6 years ago

This breaks in zope.preference:

File "//zope/preference/README.rst", line 362, in README.rst
Failed example:
    context = xmlconfig.string('''
        <configure
            xmlns="http://namespaces.zope.org/zope"
            i18n_domain="test">

          <preferenceGroup
              id=""
              title="User Preferences"
              />

        </configure>''', context)
Exception raised:
    Traceback (most recent call last):
...
      File "//src/zope/configuration/fields.py", line 44, in _validate
        raise ValidationError(value).with_field_and_value(self, value)
    ZopeXMLConfigurationError: File "<string>", line 6.6-9.12
        ConfigurationError: ('Invalid value for', 'id', '')

In this package, we have contradictory tests, expecting fromUnicode to behave one way, and validation to behave another, because fromUnicode didn't previously validate (see #28).

I think we have to allow empty strings in validation (which is what zope.schema does).

cf #35

jamadden commented 6 years ago

This looks like a bug in zope.preference too, because this snippet also breaks:

    context = xmlconfig.string('''
        <configure
            xmlns="http://namespaces.zope.org/zope"
            i18n_domain="test">

          <preferenceGroup
              id="ZMISettings2.Folder"
              title="Folder Settings"
              schema="zope.preference.README.IFolderSettings"
              />

        </configure>''', context)

The problem is that it's using a dotted name for id, but the schema declares id to be of type PythonIdentifier, which is clearly not correct.