Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arnaudiko opened this issue Dec 1, 2022 · 4 comments

Comments

@arnaudiko
Copy link

arnaudiko commented Dec 1, 2022

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-
Copy link
Owner

amol- commented Dec 9, 2022

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
Copy link
Author

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-
Copy link
Owner

amol- commented Dec 11, 2022

Version 0.9.0 should include a fix for this

@amol- amol- closed this as completed Dec 11, 2022
@arnaudiko
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants