plone / plone.restapi

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

NoneType' object has no attribute 'getProperty': when searching users #1774

Closed djay closed 2 months ago

djay commented 2 months ago

Problem

Some how you can get your site into a situation where you can no longer search users

How to reproduce

Not sure yet how this came about but we suspect its a combination of switching to email login and/or generated user ids and then deleting some users. This seemed to result in user properties not being deleted by the users in acl_users source were deleted.

After this you end up getting the following exception on a user search.

{
  "message": "'NoneType' object has no attribute 'getProperty'",
  "traceback": [
    "File \"/app/eggs/Zope-5.8.5-py3.9.egg/ZPublisher/WSGIPublisher.py\", line 181, in transaction_pubevents",
    "    yield",
    "",
    "  File \"/app/eggs/Zope-5.8.5-py3.9.egg/ZPublisher/WSGIPublisher.py\", line 391, in publish_module",
    "    response = _publish(request, new_mod_info)",
    "",
    "  File \"/app/eggs/Zope-5.8.5-py3.9.egg/ZPublisher/WSGIPublisher.py\", line 285, in publish",
    "    result = mapply(obj,",
    "",
    "  File \"/app/eggs/Zope-5.8.5-py3.9.egg/ZPublisher/mapply.py\", line 98, in mapply",
    "    return debug(object, args, context)",
    "",
    "  File \"/app/eggs/Zope-5.8.5-py3.9.egg/ZPublisher/WSGIPublisher.py\", line 68, in call_object",
    "    return obj(*args)",
    "",
    "  File \"/app/eggs/plone.rest-2.0.1-py3.9.egg/plone/rest/service.py\", line 22, in __call__",
    "    return self.render()",
    "",
    "  File \"/app/eggs/plone.restapi-8.43.4.dev0-py3.9-linux-x86_64.egg/plone/restapi/services/__init__.py\", line 19, in render",
    "    content = self.reply()",
    "",
    "  File \"/app/eggs/plone.restapi-8.43.4.dev0-py3.9-linux-x86_64.egg/plone/restapi/services/users/get.py\", line 175, in reply",
    "    users = self._get_filtered_users(",
    "",
    "  File \"/app/eggs/plone.restapi-8.43.4.dev0-py3.9-linux-x86_64.egg/plone/restapi/services/users/get.py\", line 152, in _get_filtered_users",
    "    return self._sort_users(users)",
    "",
    "  File \"/app/eggs/plone.restapi-8.43.4.dev0-py3.9-linux-x86_64.egg/plone/restapi/services/users/get.py\", line 80, in _sort_users",
    "    return sorted(",
    "",
    "  File \"/app/eggs/plone.restapi-8.43.4.dev0-py3.9-linux-x86_64.egg/plone/restapi/services/users/get.py\", line 81, in <lambda>",
    "    users, key=lambda x: normalizeString(x.getProperty(\"fullname\", \"\"))"
  ],
  "type": "AttributeError"

Proposed solution

Seems to be related to this code - https://github.com/plone/plone.restapi/commit/f77182b5700d059b6aee0f8f0bcc7a3fa29e3696

Specifically this check was removed https://github.com/plone/plone.restapi/commit/f77182b5700d059b6aee0f8f0bcc7a3fa29e3696#diff-04e041a4f39e375b78c8add4e71438d9d78988fd9c5e30e69cbbd51e9d09553aL74

There are likely two parts to a fix.

davisagli commented 2 months ago

Specifically this check was removed

Not sure what you mean, that check is still there on both the 8.x and main branches.

To me it looks like None is already filtered out correctly in _get_users, but the code is missing a similar filter in _principal_search_results