[FIX] base: Replace unreliable reference count through ORM by SQL

When the ORM is cleaning up related attachments upon record deletion, the
search() method hides the attachment of the record that is being deleted.
If the same file is used exactly once in another attachment, the reference
count will be 1 and the file will be deleted.
This commit is contained in:
Stefan Rijnhart 2015-03-03 17:10:54 +01:00 committed by Martin Trigaux
parent 56f3f01491
commit 4781deb5b6
1 changed files with 3 additions and 1 deletions

View File

@ -108,7 +108,9 @@ class ir_attachment(osv.osv):
return fname
def _file_delete(self, cr, uid, location, fname):
count = self.search(cr, 1, [('store_fname','=',fname)], count=True)
# using SQL to include files hidden through unlink or due to record rules
cr.execute("SELECT COUNT(*) FROM ir_attachment WHERE store_fname = %s", (fname,))
count = cr.fetchone()[0]
if count <= 1:
full_path = self._full_path(cr, uid, location, fname)
try: