amol- / depot

Toolkit for storing files and attachments in web applications
MIT License
161 stars 41 forks source link

[SQLALCHEMY] Delete multiple row with query system don't delete the associated files #77

Closed arnaudiko closed 1 year ago

arnaudiko commented 1 year ago

I use the SqlAlchemy ORM system. When I get an object and I delete it, the associated file is deleted to.

d = DBSession.query(Document).filter_by(name=u_('Foo2')).first()
DBSession.delete(d)

But when I create query to delete multiple row, row are deleted in the db but the associated files are not deleted

DBSession.query(Document).filter_by(name=u_('Foo2')).delete()
DBSession.commit()
amol- commented 1 year ago

The session doesn't know which objects the query will delete on the DB, so it has no way to track and update them. Have you tried providing delete(synchronize_session="fetch") ? That should make so that the session does two queries, one to check which objects will be deleted, and thus update the session, and one to actually delete them. In that case DEPOT might work.

arnaudiko commented 1 year ago

Hi,

Thanks for your feedback I already try to use query.delete(synchronize_session="fetch"). Items are deleted from the database but not from the file system.

amol- commented 1 year ago

Version 0.9.0 should include a fix for this

arnaudiko commented 1 year ago

Hi,

I tried the latest version (0.9.0) but It's still not working

  query.delete(synchronize_session='fetch')
  self.db.session.flush()
  self.db.session.commit()

This code, delete rows in database but not the associated files