Fixes for autoflush

Apparently, some newer versions of one or more of the used frameworks (probably flask-sqlalchemy) resulted in autoflush now being the default behavior. This breaks some our code.