Closed
Description
Preconditions
- All current Magento 2 versions (2.0, 2.1.1)
Steps to reproduce
-
Let a commit callback throw an exception
Example:
- create a new search engine
<type name="Magento\Search\Model\AdapterFactory"> <arguments> <argument name="adapters" xsi:type="array"> <item name="dummy" xsi:type="string">Magento\Framework\Search\Adapter\Mysql\Adapter</item> </argument> </arguments> </type>
- Do not register a corresponding indexer handler for
Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory
- The commit callback from the fulltext indexer plugin will cause an exception "There is no such indexer handler: dummy"
-
Trigger this commit (for example, save a product)
Expected result
- Exception from the commit callback is thrown and can be catched later (for ex. by PHPUnit)
Actual result
rollback()
is called aftercommit()
already has been called for the same transaction, resulting in an “Asymmetric transaction rollback error” exception when Magento tries to commit or rollback the last transaction on the stack.
Possible solution
-
create a new exception type for exceptions during commit callbacks,
AfterCommitException
-
Replace
throw $e
withthrow new AfterCommitException(null, null, $e);
inAbstractResource::commit()
-
In plugins that register commit callbacks, handle these exceptions separately:
} catch (AfterCommitException $e) { throw $e->getPrevious(); } catch (\Exception $e) { $productResource->rollBack(); throw $e; }
Please let me know if this solution would be acceptable, before I create a PR