Open pcolaianni opened 2 years ago
Thanks for the report @pcolaianni . This is due to incomplete documentation, but the current REST API should be read-only. It doesn't officially support changing state. The error you found is part of the reason why. There has been ongoing work on implementing a new REST API that does allow POSTing data: https://github.com/aiidateam/aiida-restapi
I am personally not involved in that work, but maybe @chrisjsewell or @flavianojs can shed some light on the status?
Hey @pcolaianni , I just updated the documentation of the plugin See https://aiida-restapi.readthedocs.io/en/latest/user_guide/tutorial.html for how to use it.
@sphuber We could close this issue or we could keep it open as a reminder that POST
to endpoints that don't support it (I guess all endpoints except the querybuilder
one?) should fail.
We could close this issue or we could keep it open as a reminder that POST to endpoints that don't support it (I guess all endpoints except the querybuilder one?) should fail.
I will quickly open a PR to update the aiida-core
docs on extending the REST API saying that only read-only operations are supported.
Hey @pcolaianni, apologies for just glancing over your issue - after properly reading through your issue description I do agree it points to an issue in the current REST API implementation.
There are examples of others who extended the REST API to POST requests, such as the codebase for the AiiDA-Ginestra integration.
I.e. it is possible that this bug was introduced more recently and went unnoticed because, currently, the only POST endpoint (/querybuilder
) in the REST API that ships with aiida-core does not involve the creation of nodes in the AiiDA database.
I just tried creating multiple nodes using the aiida-restapi
plugin, and that worked fine.
Furthermore, the aiida-restapi
already includes an endpoint for creating a singlefiledata via multipart form - you can try it out using the swagger client at /docs
(just follow the tutorial I linked above)
We also just made aiida-restapi
compatible with aiida 2.0 (for aiida-1.x compatible version use tag v0.1.0a0).
Describe the bug
I am following the tutorial at https://aiida.readthedocs.io/projects/aiida-core/en/latest/internals/rest_api.html#extending-the-rest-api
When POSTing, it works. The first time. The second time, it raises an exception:
Steps to reproduce
Steps to reproduce the behavior:
curl http://localhost:6000/api/v4/new-endpoint/ -X POST
curl http://localhost:6000/api/v4/new-endpoint/ -X POST
Expected behavior
The second call should create a new object and return the id.
Your environment
Other relevant software versions, e.g. Postres & RabbitMQ
Additional context
I found out about this issue while trying to extend the API to support the upload of files. In my case, I am dealing with data of type
SinglefileData
. At first I thought the problem was uploading the same file several times. But then I tried uploading two different files, and it fails anyway. Also uploading the same file in two different runs ofapp.py
works. AiiDA correctly creates two nodes for the same uploaded file. Therefore the problem seems to be with managing the backend session and theDbUser
object.