I am working on plugin to Drupal Commerce, and I started getting this error:

DatabaseTransactionOutOfOrderException: in DatabaseConnection->rollback() (line 1058 of /Library/WebServer/Documents/includes/database/database.inc).

Can anyone shed some light on what this error means? If I install a fresh drupal and reinstall my plugin, is that likely to clear things up?

Any advice?


closed as too broad by Clive Jan 8 at 11:12

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you using db_transaction() in your custom code? – Clive May 19 '14 at 16:54
  • No, I am not. I am using commerce_payment_transaction_new,commerce_payment_transaction_save and a few other calls from the commerce_payment.module – iewebguy May 19 '14 at 17:07
  • Any chance you can edit the code into the question? At a guess those functions are being used in way that's causing an overlap in transactions, then one fails and everything blows up. It's hard to say without seeing the code though – Clive May 19 '14 at 17:08
  • I can't post the code at this time -- Could the overlap be from prior orders? (this is a payment plugin) could it get out of sync that way? – iewebguy May 19 '14 at 17:16
  • Impossible to say without seeing the code that raises the error. – David Thomas May 19 '14 at 22:36

The DatabaseTransactionOutOfOrderException exception is part of the rollback() method (DatabaseConnection class) and it is thrown when a rollback() resulted in other active transactions being rolled-back instead of rollback to correct earlier savepoint.

You may debug it checking the backtrace when this exception is thrown.

In example defining the following hook:

 * Implements hook_watchdog().
function foo_watchdog($log_entry) {
  if ($log_entry['type'] == 'php' && $log_entry['severity'] <= WATCHDOG_WARNING) {
    // Old school
    // var_dump(debug_backtrace()); // Optionally add: exit();

    // Devel: Log the backtrace into temporary file: drupal_debug.txt
    // Locate via: $ drush eval "echo file_directory_temp() . '/drupal_debug.txt'"
    function_exists('dd') && dd(debug_backtrace());

Don't forget to install Devel module (for dd) and clear the cache before testing it.

Then try to reproduce the problem and then check your /tmp/drupal_debug.txt debug file which should contain something like (section _drupal_exception_handler):

[function] => _drupal_exception_handler
[args] => Array
        [0] => DatabaseTransactionOutOfOrderException Object
                [file:protected] => /var/www/includes/database/database.inc
                [line:protected] => 1071
                [trace:Exception:private] => Array
                        [0] => Array
                                [file] => /var/www/includes/database/database.inc
                                [line] => 1933
                                [function] => rollback
                                [class] => DatabaseConnection
                        [1] => Array
                                [file] => /var/www/sites/all/modules/contrib/commerce/modules/order/includes/commerce_order.controller.inc
                                [line] => 123
                                [function] => rollback
                                [class] => DatabaseTransaction
                        [2] => Array
                                [file] => /var/www/sites/all/modules/contrib/commerce/modules/order/commerce_order.module
                                [line] => 734
                                [function] => save
                                [class] => CommerceOrderEntityController
                                [type] => ->

So based on the above example, you know that something goes wrong in commerce_order.module on line 734 during CommerceOrderEntity save.

If it's still not clear, other suggestion is to enable MySQL query logging and check the suspicious queries which are sent.

Not the answer you're looking for? Browse other questions tagged or ask your own question.