plone / plone.restapi

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

next-previous feature errors on collections #924

Closed sneridagh closed 4 years ago

sneridagh commented 4 years ago

Access to a collection (spotted in news/events Plone site default items), The API throws an 500:

  Module plone.app.dexterity.behaviors.nextprevious, line 88, in getNextItem
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
sneridagh commented 4 years ago

@rodfersou please take a look if you can fix it quickly.

rodfersou commented 4 years ago

@sneridagh it just works here:

$ http http://localhost:8080/Plone/news/events Accept:application/json -a admin:admin | jq '.previous_item'
{
  "@id": "http://localhost:8080/Plone/news",
  "@type": "Folder",
  "description": "Site News",
  "title": "News"
}

 ...src/kitconcept/contentcreator   master ✔ 
$ http http://localhost:8080/Plone/news/events Accept:application/json -a admin:admin | jq '.next_item'    
{
  "@id": "http://localhost:8080/Plone/Members",
  "@type": "Folder",
  "description": "Site Users",
  "title": "Users"
}
rodfersou commented 4 years ago

okay, now I see the problem:

$ http http://localhost:8080/Plone/events/aggregator Accept:application/json -a admin:admin                  
HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 110
Content-Type: text/plain
Date: Tue, 28 Apr 2020 08:27:03 GMT
Server: waitress

Internal Server Error

The server encountered an unexpected internal server error

(generated by waitress)
rodfersou commented 4 years ago

@sneridagh turns out that the problem is that the folder is set as unordered, and it is returning None when try to get the object position: https://github.com/plone/plone.app.contenttypes/blob/master/plone/app/contenttypes/setuphandlers.py#L225

we can treat the exception and don't show next/previous in this case.. although the right thing should be to fix the initial content creation at p.a.contenttypes.

sneridagh commented 4 years ago

@rodfersou that is an use case we have to catch in p.restapi.