Rollback only if a transaction is on

This avoids "could not rollback" error messages covering the real error, as it happened to Sevgi.
The tests are green: https://ci.openquake.org/job/zdevel_oq-engine/797/