SQL error masked by TypeError