fix possible unicode errors during __repr__
app handle_exception: ensure db objects are in a valid session

get objects in session before removing it, and merge them in a new
session before handlers try to access them