pyeve / eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
http://eve-sqlalchemy.readthedocs.io
Other
232 stars 70 forks source link

Delete ORM objects created in other request #93

Open jeroenes opened 8 years ago

jeroenes commented 8 years ago

This is probably something that is staring me in the face somewhere in a doc, but it seems not possible for me to delete objects in a custom view. (and I need that view because I cannot find a way to expose sqlalchemy functions through Eve).

Now I understand things get complicated with deletes when you are working with requests, so I appreciate there may be no simple answer. Things are even more complicated because the core of this function needs to happen in an another spawned thread as it takes up quite some time ( I allow consumers to poll an endpoint for progress updates).

I have tried the following:

  1. deleting in the view before the functions gets called. This results in the session going haywire. One of the parent objects throws errors when accessed. Probably stuff does not get finished before my thread is spawned.
  2. deleting within the spawned thread results in "not attached to this session" errors
  3. setting ID to 'None' and deleting objects from the parent in the ORM only (setting the collection empty) . Does not seem to have any impact at all, the objects retain there IDs and the parent collection remains filled.

I hope there is something obvious that I have missed! Any wisdom that you might be able to share would be highly appreciated!

Thanks, Jeroen