Fixed using thread-local db sessions incorrectly