Fix 4309 non orphaned attachments

Here is the smallest possible changeset that fixes #4309 
res_id=0 is a corner case that seemed not really handled