clean up sqlalchemy exception code
Merge pull request #5318 from ticoann/new_sqlarchemy

clean up sqlalchemy exception code