I was working on one of the needs in which I needed to add some new data to the catalog_eav_attribute table. And for that, I've created an update query that will be executed from DataPatch, and the query will be executed to update data in the database when the code is deployed to the server.
So I have added below code:
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
$connection = $this->resourceConnection->getConnection();
try {
if ($connection->tableColumnExists('catalog_eav_attribute', 'used_in_feed') === true) {
foreach ($this->attributes as $attribute) {
$query = "UPDATE catalog_eav_attribute SET used_in_feed = 1 WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE entity_type_id = 4 AND attribute_code = '" . $attribute . "')";
$connection->query($query);
}
}
} catch (\Exception $e) {
$connection->rollBack();
}
$connection->commit();
$this->moduleDataSetup->getConnection()->endSetup();
}
Issue: I was experiencing an "Asymmetric Transaction Rollback" after running this code.
Solution: Because DataPatch is already in the transaction, there is no need for a commit. And when we add a commit to our code, it fails to get anything to commit, resulting in this error, and we always encounter the "Asymmetric Transaction Rollback" OR "Asymmetric Transaction Commit" problem.
Comments
Post a Comment