magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Exception 'There is no active transaction' on save custom EAV model #6541

Closed DmitriiChukhnov1 closed 7 years ago

DmitriiChukhnov1 commented 8 years ago

Preconditions

  1. Magento CE 2.1.1 (also CE 2.1.0)
  2. PHP 5.6.24
  3. MySQL 5.7.13

    Steps to reproduce

  1. Create custom EAV model.
  2. Save first entity of custom EAV model.

    Expected result

  1. Entity saved without any error messages.

    Actual result

  1. Entity saved correctly.
  2. Error message in log:
    `[2016-09-08 11:11:49] main.CRITICAL: exception 'PDOException' with message 'There is no active transaction' in //vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:324 Stack trace:

    0 //vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php(324): PDO->rollBack()

    1 //vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(524): Zend_Db_Adapter_Pdo_Abstract->_rollBack()

    2 //vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(268): Zend_Db_Adapter_Abstract->rollBack()

    3 //vendor/magento/framework/Model/ResourceModel/AbstractResource.php(99): Magento\Framework\DB\Adapter\Pdo\Mysql->rollBack()

    4 //var/generation///Model/ResourceModel/StockRecord/Interceptor.php(583): Magento\Framework\Model\ResourceModel\AbstractResource->rollBack()

    5 //vendor/magento/module-eav/Model/Entity/AbstractEntity.php(1147): \\Model\ResourceModel\StockRecord\Interceptor->rollBack()

    6 //vendor/magento/framework/Interception/Interceptor.php(74): Magento\Eav\Model\Entity\AbstractEntity->save(Object(\\Model\StockRecord))

    7 //vendor/magento/framework/Interception/Chain/Chain.php(70): \\Model\ResourceModel\StockRecord\Interceptor->___callParent('save', Array)

    8 //vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('\...', 'save', Object(\\Model\ResourceModel\StockRecord\Interceptor), Array, 'clean_cache')

    9 //vendor/magento/framework/App/Cache/FlushCacheByTa.php(60): \\Model\ResourceModel\StockRecord\Interceptor->Magento\Framework\Interception{closure}(Object(\\Model\StockRecord))

    10 //vendor/magento/framework/Interception/Interceptor.php(142): Magento\Framework\App\Cache\FlushCacheByTa->aroundSave(Object(\\Model\ResourceModel\StockRecord\Interceptor), Object(Closure), Object(\\Model\StockRecord))

    11 //var/generation///Model/ResourceModel/StockRecord/Interceptor.php(429): \\Model\ResourceModel\StockRecord\Interceptor->___callPlugins('save', Array, Array)

    12 //vendor/magento/framework/Model/AbstractModel.php(631): \\Model\ResourceModel\StockRecord\Interceptor->save(Object(\\Model\StockRecord))

    13 //app/code///Model/StockRecord.php(32): Magento\Framework\Model\AbstractModel->save()

    ...`

  3. After that on each load of custom EAV model throws exception:
    `2016/09/08 14:38:31 [error] 3697#3697: *715 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'Exception' with message 'User Error: Some transactions have not been committed or rolled back in //vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 3774' in //vendor/magento/framework/App/ErrorHandler.php:61 Stack trace:

    0 [internal function]: Magento\Framework\App\ErrorHandler->handler(256, 'Some transactio...', '/...', 3774, Array)

    1 //vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(3774): trigger_error('Some transactio...', 256)

    2 [internal function]: Magento\Framework\DB\Adapter\Pdo\Mysql->__destruct()

    3 {main}

    thrown in //vendor/magento/framework/App/ErrorHandler.php on line 61" while reading upstream, client: 127.0.0.1, server: www.magento22.ru, request: "GET /admin_1jm9bf//stockrecord/edit/id/1/key/44ab1579b65f9844dd0900587fff2ae3fe9308924d2bb2a52f7c078b374e3ed4/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php5.6-fpm.sock:", host: "www.magento22.ru", referrer: "http://www.magento22.ru/admin_1jm9bf//stockrecord/index/key/a5b189dfe48288c212ecfe37c996d21491c3f42dcc6cdca21a48eab6424cb7fb/"`

    Important

If disable eav cache ("EAV types and attributes") the problem disappears.

Additional info

  1. Custom resource model extends "\Magento\Eav\Model\Entity\AbstractEntity".
  2. Custom collection extends "\Magento\Eav\Model\Entity\Collection\AbstractCollection".
  3. Entity type declaration:
public function getDefaultEntities()
    {
        $entities = [
            'custom_eav' => [
                'entity_model' => '<vendor>\<model>\Model\ResourceModel\StockRecord',
                'attribute_model' => 'Magento\Eav\Model\Entity\Attribute',
                'table' => 'custom_eav_entity',
                'increment_model' => 'Magento\Eav\Model\Entity\Increment\NumericValue',
                'entity_attribute_collection' => 'Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection',
                'attributes' => [
                    'uid' => [
                        'type' => 'static',
                        'label' => 'Uid',
                        'input' => 'text',
                        'required' => true,
                        'unique' => true,
                        'sort_order' => 10,
                    ],
                ],
            ],
        ];
        return $entities;
    }
koenner01 commented 8 years ago

I'm having the same issue and disabling the EAV cache does indeed solve the problem (for now)

Using: Magento CE 2.1.1 PHP 7.0

maxlaberge commented 8 years ago

I am having the same issue with a custom EAV model, exactly as described. Disabling the EAV cache did resolve the issue.

Using: Magento CE 2.1.1 PHP 7.0

DmitriiChukhnov1 commented 8 years ago

To disable eav cache only for custom EAV model, I am using this di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Eav\Model\Entity\AttributeCache">
        <arguments>
            <argument name="unsupportedTypes" xsi:type="array">
                <item name="custom_eav" xsi:type="string">custom_eav</item>
                <item name="custom_eav_second" xsi:type="string">custom_eav_second</item>
            </argument>
        </arguments>
    </type>
</config>
koenner01 commented 8 years ago

Adding the unsupportedType in the di.xml worked like a charm for me! I don't really know what the EAV caching entails and I'm not sure if this has a big influence on performance on the frontend.

NicolaF commented 7 years ago

Same issue here. First EAV save after cache flush fails. I'm on Magento CE 2.1.2

Kudja commented 7 years ago

Hi there - I have same issue on Magento 1.9.3 and we solved it by disabling persistant flag on connections, which is passed to PDO object as PDO::ATTR_PERSISTENT => true later in adapter

Not sure why, but enabling/disabling persistent in php.ini not helping, just after I removed <persistent>1</persistent> from connection section in local.xml it starts to work well

Also we worked on older php7.0 versions and looks like this happen after last upgrade

[root@web ~]# php -v
PHP 7.0.16 (cli) (built: Feb 14 2017 17:22:12) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.16, Copyright (c) 1999-2017, by Zend Technologies
orlangur commented 7 years ago

Buggy EAV Attribute Cache mechanism was removed on Magento 2.2.0 branch: https://github.com/magento/magento2/commit/3ae7c1909daad96d5a0ad6ab7048455448ba7480

This is not something that could be backported due to BC constraints, as a workaround you can try just to disable this cache type.

TheRealJAG commented 6 years ago

I had a similar problem in Magento ver. 1.9.3.7 when editing products. To resolve this I disabled all caches and I was able to modify products.

MilenV commented 9 months ago

Hello Team,

We caught below error which seems related to this ticket.

Exception catched for order '8000060764' while executing action '\Xtento\TrackingImport\Model\Import\Action\Order\Shipment::ship':
There is no active transaction

Can you please check and advise on it?

Regards, Milen Velinov