0

I have had this issue intermittently (1 in about 20-30 orders) for a while now not sure when it started possible anywhere from version 2.1.7 and not sure what has caused this. I am using Form Integration from Ebizmarts Sage Pay Suite module. I thought it was due to this plugin however this may not be the case and they believe it is an issue within my Magento instance.

Orders do seem to work however error is shown on checkout success and anywhere from 2 - 7 emails seem to end up in both our and customer inboxes when this occurs.

The following error is shown in my logs when above occurs:

SagePaySuiteLogger.Exception: Unique constraint violation found

Full Trace:

[2018-03-29 08:26:44] SagePaySuiteLogger.Exception: Unique constraint violation found
#0 /home/sites/magento/public_html/vendor/magento/framework/Model/AbstractModel.php(647): Magento\Framework\Model\ResourceModel\Db\AbstractDb->save(Object(Magento\Sales\Model\Order\Payment\Transaction))
#1 /home/sites/magento/public_html/vendor/ebizmarts/sagepaysuite/Model/OrderUpdateOnCallback.php(72): Magento\Framework\Model\AbstractModel->save()
#2 /home/sites/magento/public_html/vendor/ebizmarts/sagepaysuite/Controller/Form/Success.php(172): Ebizmarts\SagePaySuite\Model\OrderUpdateOnCallback->confirmPayment('B1B897CC-D94C-4...')
#3 /home/sites/magento/public_html/vendor/magento/framework/App/Action/Action.php(107): Ebizmarts\SagePaySuite\Controller\Form\Success->execute()
#4 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#5 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->___callParent('dispatch', Array)
#6 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#7 /home/sites/magento/public_html/generated/code/Ebizmarts/SagePaySuite/Controller/Form/Success/Interceptor.php(26): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->___callPlugins('dispatch', Array, Array)
#8 /home/sites/magento/public_html/vendor/magento/framework/App/FrontController.php(55): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#9 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#10 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#11 /home/sites/magento/public_html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#12 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#13 /home/sites/magento/public_html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#16 /home/sites/magento/public_html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, NULL)
#17 /home/sites/magento/public_html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#18 /home/sites/magento/public_html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#19 /home/sites/magento/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#20 {main}

I have looked at below link as seems to be a very similar issue however my tables look in tact according to the images in this post: https://magecomp.com/blog/fix-unique-constraint-violation-found-magento-2-checkout-after-migration/

The only difference that can be seen is that my prefix entry is null for the meta_id referring to entries for store_id's 0 and 1 and i have max / warning values set for store_id 2.

Can anyone suggest what may be causing this issue with my checkout or how to help further debug this issue?

Code that throws error

    try {
        if (!$this->isModified($object)) {
            $this->processNotModifiedSave($object);
            $this->commit();
            $object->setHasDataChanges(false);
            return $this;
        }
        $object->validateBeforeSave();
        $object->beforeSave();
        if ($object->isSaveAllowed()) {
            $this->_serializeFields($object);
            $this->_beforeSave($object);
            $this->_checkUnique($object);
            $this->objectRelationProcessor->validateDataIntegrity($this->getMainTable(), $object->getData());
            if ($this->isObjectNotNew($object)) {
                $this->updateObject($object);
            } else {
                $this->saveNewObject($object);
            }
            $this->unserializeFields($object);
            $this->processAfterSaves($object);
        }
        $this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
        $object->setHasDataChanges(false);
    } catch (DuplicateException $e) {
        $this->rollBack();
        $object->setHasDataChanges(true);
        throw new AlreadyExistsException(new Phrase('Unique constraint violation found'), $e);
    } catch (\Exception $e) {
        $this->rollBack();
        $object->setHasDataChanges(true);
        throw $e;
    }

Or what line causes the throw new AlreadyExistsException(new Phrase('Unique constraint violation found'), $e); to be thrown so i can maybe log some information about why it is thrown?

14
  • Did you find a solution to this as I am having the exact same issue
    – Goose84
    Commented Apr 4, 2018 at 12:42
  • Literally been putting checkouts through all day today to see if i can make it happen. Do you use Ebizmarts sage pay? It very rarely happens, can you explain a bit more about when yours happens also?
    – harri
    Commented Apr 4, 2018 at 12:43
  • I have Magento 2.2.2 with Ebizmarts Sagepay 1.2.4. Sagepay states: "Transaction completed but Vendor systems returned INVALID or ERROR in response to notification POST. Transaction CANCELLED by the Vendor. " When looking in the logs we have ["Ebizmarts\\SagePaySuite\\Controller\\Server\\Notify::cancelOrder",254] [] SagePaySuiteLogger.Exception: Unique constraint violation found
    – Goose84
    Commented Apr 4, 2018 at 12:48
  • Yeah seems very similar. Have you contacted Ebizmarts? They are telling me it is my magento. Where did you get this information ""Transaction completed but Vendor systems returned INVALID or ERROR in response to notification POST. Transaction CANCELLED by the Vendor. "?
    – harri
    Commented Apr 4, 2018 at 12:50
  • But yeah im on 2.2.3 with 1.2.4 but have had this issue a while so would of existed when i was on 2.2.1 at least
    – harri
    Commented Apr 4, 2018 at 12:51

1 Answer 1

1

Please use version 1.2.6 for Magento 2.2.x. Upgrade via composer.

1
  • Will try as soon as i get a chance thanks for the update.
    – harri
    Commented Apr 6, 2018 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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