I had the same problem. I spent hours debugging and investigating what is going on. At the end I confirmed that nothing was wrong with my code, and that there was something corrupt with the database. I reinstalled the DB schema and that resolved the issue for me.