Fix to an error where samples were tried to be saved before their related subjects were actually stored in the database