plone / plone.restapi

RESTful API for Plone.
http://plonerestapi.readthedocs.org/
84 stars 75 forks source link

Patching /@registry value array raises WrongType error #1658

Closed Sakoes closed 1 year ago

Sakoes commented 1 year ago

Problem: Patching an array in the /@registry endpoint raises a WrongType error as the array is interpreted as a tuple.

Context: I am trying to patch registry entries for cache purging options. This is the registry entry:

{
      "name": "plone.cachepurging.interfaces.ICachePurgingSettings.cachingProxies", 
      "schema": {
        "properties": {
          "additionalItems": true, 
          "description": "Geef de URL's op van elke cacheserver waarnaar PURGE verzoeken moeten worden gestuurd.", 
          "factory": "Tuple", 
          "items": {
            "description": "", 
            "factory": "URL", 
            "title": "", 
            "type": "string", 
            "widget": "url"
          }, 
          "title": "Caching servers", 
          "type": "array", 
          "uniqueItems": true
        }
      }, 
      "value": [
        "http://purge_proxy:8000"
      ]
    }

However, when I want to patch the value:

url = "http://localhost:6003/Plone/@registry"
auth = ('admin', 'admin')
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
data = {
    "plone.cachepurging.interfaces.ICachePurgingSettings.cachingProxies": [
        "http://new_purge_proxy:8000",
        "http://another_purge_proxy:9000"
    ]
}
response = requests.patch(f"{url}", auth=auth, headers=headers,  json=data)

I get following error:

error: {'message': "(['http://purge_proxy:8000', 'http://new_purge_proxy:8000', "
            "'http://another_purge_proxy:9000'], <class 'tuple'>, 'value')",
 'traceback': ['File '
               '"/buildout/eggs/Zope-5.7-py3.8.egg/ZPublisher/WSGIPublisher.py", '
               'line 167, in transaction_pubevents',
               '    yield',
               '',
               '  File '
               '"/buildout/eggs/Zope-5.7-py3.8.egg/ZPublisher/WSGIPublisher.py", '
               'line 376, in publish_module',
               '    response = _publish(request, new_mod_info)',
               '',
               '  File '
               '"/buildout/eggs/Zope-5.7-py3.8.egg/ZPublisher/WSGIPublisher.py", '
               'line 271, in publish',
               '    result = mapply(obj,',
               '',
               '  File '
               '"/buildout/eggs/Zope-5.7-py3.8.egg/ZPublisher/mapply.py", line '
               '85, in mapply',
               '    return debug(object, args, context)',
               '',
               '  File '
               '"/buildout/eggs/Zope-5.7-py3.8.egg/ZPublisher/WSGIPublisher.py", '
               'line 68, in call_object',
               '    return obj(*args)',
               '',
               '  File '
               '"/buildout/eggs/plone.rest-2.0.0-py3.8.egg/plone/rest/service.py", '
               'line 22, in __call__',
               '    return self.render()',
               '',
               '  File '
               '"/buildout/eggs/plone.restapi-8.32.6-py3.8.egg/plone/restapi/services/__init__.py", '
               'line 19, in render',
               '    content = self.reply()',
               '',
               '  File '
               '"/buildout/eggs/plone.restapi-8.32.6-py3.8.egg/plone/restapi/services/registry/update.py", '
               'line 25, in reply',
               '    registry[key] = value',
               '',
               '  File '
               '"/buildout/eggs/plone.registry-1.2.1-py3.8.egg/plone/registry/registry.py", '
               'line 51, in __setitem__',
               '    self.records[name].value = value',
               '',
               '  File '
               '"/buildout/eggs/plone.registry-1.2.1-py3.8.egg/plone/registry/record.py", '
               'line 82, in _set_value',
               '    field.validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_bootstrapfields.py", '
               'line 298, in validate',
               '    self._validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_field.py", '
               'line 783, in _validate',
               '    super(Collection, self)._validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_bootstrapfields.py", '
               'line 513, in _validate',
               '    super(MinMaxLen, self)._validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_bootstrapfields.py", '
               'line 452, in _validate',
               '    super(Iterable, self)._validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_bootstrapfields.py", '
               'line 437, in _validate',
               '    super(Container, self)._validate(value)',
               '',
               '  File '
               '"/buildout/eggs/zope.schema-6.2.1-py3.8.egg/zope/schema/_bootstrapfields.py", '
               'line 347, in _validate',
               '    raise WrongType('],
 'type': 'WrongType'}

Notes: It looks like the array with the new values gets interpreted as a tuple instead of an array. I tried the obvious by changing the array in my data to a tuple

data = {
    "plone.cachepurging.interfaces.ICachePurgingSettings.cachingProxies": (
        "http://new_purge_proxy:8000",
        "http://another_purge_proxy:9000"
    )
}

But it raises the same error

Sakoes commented 1 year ago

Apparently this is a duplicate of an already fixed issue: https://github.com/plone/plone.restapi/issues/1575. However, since I am still experiencing this issue, I will leave this issue open until I have found I why. My best guess is that I might be using an older version of the package that doesn't have the fix

Sakoes commented 1 year ago

Solution is to upgrade to the latest version