[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:
parent
56f3f01491
commit
4781deb5b6
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue