Check hasattr() first

 #1338