Bugzilla doesn't roll back transactions on errors when using eval

Gervase Markham gerv at mozilla.org
Tue Aug 27 10:08:21 UTC 2013


I've just found a long-standing bug in a Bugzilla extension I maintain.

Regularly, this extension tries to create a series of bugs. Sometimes
the data for one or more of those bugs was bad (e.g. invalid version)
and this failed. This caused the entire job to die. So I wrapped the
Bugzilla::Bug->create() call in eval {} and handled the error, then
proceeded. I thought this was the right thing to do.

However, it turns out that if you are using eval(), then
Bugzilla::Bug->create() will start a transaction, but the Bugzilla error
code will not roll it back or close it:

Error.pm, lines 57-60, function _throw_error:

    # Make sure any transaction is rolled back (if supported).
    # If we are within an eval(), do not roll back transactions as we
    # are eval'uating some test on purpose.
    $dbh->bz_rollback_transaction() if ($dbh->bz_in_transaction() &&
!_in_eval());

The result was that I was still in a transaction after handling the
error. The rest of my code created more bugs, opening and closing
transactions each time, but when it all got to the end, there was still
an open transaction - and we don't call commit() until all transactions
are closed. So none of my bugs actually got created in the DB (although
the auto_increment showed that their bug numbers had been allocated)!

The fix was to manually close the transaction when I had a failure, but
the need to do this was not at all obvious.

This error behaviour seems wrong to me (in that it exposes weird
requirements on the user of an API which are not obvious and easy to
miss or get wrong), but I'm not entirely sure what the best fix is.
Comments?

Gerv
_______________________________________________
dev-apps-bugzilla mailing list
dev-apps-bugzilla at lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-apps-bugzilla



More information about the developers mailing list