fix attachment query