# Attachement again (the last one)

**URL:** https://discuss.tryton.org/t/attachement-again-the-last-one/9026
**Category:** Developer
**Created:** [December 19, 2025, 10:43am UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026 "2025-12-19T10:43:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 10:43am UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/1 "2025-12-19T10:43:42Z")

</div>

What is the right way to delete an attachment, I think that the file deleted stays in the File system.

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [December 19, 2025, 10:48am UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/2 "2025-12-19T10:48:58Z")

</div>

Removing files is not supported yet, but there is a merge request on this subject:

> **[Remove file from filestore when setting a Binary field to None (!2200) ·...](https://foss.heptapod.net/tryton/tryton/-/merge_requests/2200)**
>
> Closes #13861

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 11:10am UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/3 "2025-12-19T11:10:39Z")

</div>

would it not be simpler that when you delete the file in the ir\_attachement view, you get the file\_name (the hash) then look to see if he is “duplicated” and it is use elsewhere (so not removing it) and if it is the last one just delete from disk ?

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [December 19, 2025, 11:34am UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/4 "2025-12-19T11:34:49Z")

</div>

We deemed your idea too complicated to implement that’s why it was never implemented.

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 1:05pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/5 "2025-12-19T13:05:54Z")

</div>

I read the proposal to commitment … you think my idea to complicated ???

pseudo code

```auto
def supress attachement (attachement_id)
    get hash of file(attachement_id->file_id)
    count ir.attachement[(hash_of_file)
    count=1 
        delete /var/lib/tryton/tryton/substr(0,2,hash)/substr(2,4,hash)/hash
    delete ir._attachment(id)

```

I guess it is less than 50 lines in proteus (with a bunch of try-except)

i’ll implement it in my install

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [December 19, 2025, 1:15pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/6 "2025-12-19T13:15:28Z")

</div>

In fact the file can be linked to another `fields.Binary` in another object and it will have the same hash, so you will have to check every Binary field in every table.

Also you can not delete directly the file because your transaction can rollback.

So yes, maybe in your specific use case your solution is simple enough but there are other usecases that we have to take into account.

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 1:24pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/7 "2025-12-19T13:24:51Z")

</div>

there is a table ir\_attachement  
id | copy\_to\_resources | create\_date | create\_uid | data | description | file\_id | link | name | resource | type | write\_date | write\_uid  
----±------------------±---------------------------±-----------±-----±------------±---------------------------------±-----±---------------------------------±------------------±-----±-----------±----------  
66 | | 2025-12-18 18:23:49.392712 | 1 | | | 45a1d192d1c49c94dfc6ca6f319854de | | contrat-manger-minou\_le\_chat.pdf | party.party,25561 | data | |

in my config files are stored on disk that pef has 45a1d192d1c49c94dfc6ca6f319854de as hash

```auto
Att=Model.get(ir.attachement)
to_del=Att.find([('id,'=',args.todelete)
the_atts=Att.find([('file_id','=',to_del.id)
hash=to_del.file_id
if (len(the_atts))>1:
        pass
else:
        os.remove (/var/lib/tryton/tryton/substr(0,2,hash)/substr(2,4,hash)/hash)
to_del.delete()

```

I am not arguing with all binary files in whatever model, just supress attachments in view

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 1:26pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/8 "2025-12-19T13:26:28Z")

</div>

when you suppress a party, a product, a move, an attachement, there is no rolling back

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [December 19, 2025, 1:37pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/9 "2025-12-19T13:37:51Z")

</div>

You do you, I don’t really care.

I’m trying to help you by pointing out:

- What you want to do is not possible currently
- But a merge request will make it possible _soon_ ™

Then you’re arguing with me because you have a better idea which work only in your specific use case (ie: through proteus and only taking into account the attachments).

I will stop this useless discussion.

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [December 19, 2025, 1:46pm UTC](https://discuss.tryton.org/t/attachement-again-the-last-one/9026/10 "2025-12-19T13:46:09Z")

</div>

i am not arguing with you because of i-do-not-know-why  
i am arguing because i asked  
**What is the right way to delete an attachment**

And you says it is complicated and somewhere in the futur (version 8 - migration forced) there will have a possibility to delete a binary.data within a configured laps time.

the question was : _how to delete a file in the file system when the attachment is delete from a object._

Yes your solution is probably better (more use case, and you can revoke your supression) but K.I.S.S is my religion. and that “bad” solution is what i need.  
it is proteus code because i am working with proteus at the moment and have no computer to test so it is some kind of fast draft.

thanks for responding
