Skip to content
Permalink
Browse files

[FIX] mail: File deletion on module uninstallation

Commit 262e001 introduced thread, message, and attachments deletion on a
module uninstallation. When removing attachments it was also removing
files in the filestore even if those files were still in use by other
attachments.

opw-1968117
  • Loading branch information...
Julien00859 committed Apr 15, 2019
1 parent c1c322d commit 26d3a448cbf52832cee98c997b1ea9300ef9cb26
Showing with 14 additions and 4 deletions.
  1. +14 −4 addons/mail/models/ir_model.py
@@ -25,13 +25,23 @@ def unlink(self):
query = "DELETE FROM mail_message WHERE model in %s"
self.env.cr.execute(query, [models])

# Get files attached solely by the models
query = """
DELETE FROM ir_attachment
WHERE res_model in %s
RETURNING store_fname
SELECT DISTINCT store_fname
FROM ir_attachment
WHERE res_model IN %s
EXCEPT
SELECT store_fname
FROM ir_attachment
WHERE res_model not IN %s;
"""
self.env.cr.execute(query, [models, models])
fnames = self.env.cr.fetchall()

query = """DELETE FROM ir_attachment WHERE res_model in %s"""
self.env.cr.execute(query, [models])
for (fname,) in self.env.cr.fetchall():

for (fname,) in fnames:
self.env['ir.attachment']._file_delete(fname)

return super(IrModel, self).unlink()

0 comments on commit 26d3a44

Please sign in to comment.
You can’t perform that action at this time.