Closed poz closed 5 months ago
Additional findings:
This also happen to DELETE
query. INSERT
query are not affected because executeInsert()
does not call connection->begin()
I look into this
Resolved in https://github.com/phalcon/cphalcon/pull/16610
Thank you to @noone-silent and thank you @poz for reporting
Describe the bug When a PDOException is throw by
Phalcon\Mvc\Model\Query::executeUpdate()
, the internal transaction did not rollback correctly and mess up the subsequent queries.To Reproduce Steps to reproduce the behavior:
$this->modelsManager->executeQuery
to update for each single row.PDOException
by updating a string value that is longer than varchar(10) (mysql strict mode)Result:
Expected behavior
Details
set sql_mode=STRICT_ALL_TABLES;
Additional context I did some investigation to the source and notice that in
Phalcon\Mvc\Model\Query
, it does not catch any exception.https://github.com/phalcon/cphalcon/blob/master/phalcon/Mvc/Model/Query.zep#L1485-L1515
I'm not familiar with zephir I've assumed that the exception is not handled properly there. It seems to leave the function instantly without calling connection->rollback when exception happens.
However if I manually called
$this->db->rollback()
right after catching the exception, the result is working as intended. I don't think this is a good workaround in case exception is happened elsewhere though.Below are the (simplified) mysql general log, which also confirms my suspicion.
Noticed how after 3rd row update, the was no more COMMIT because pdo adapater handles transaction level internally and it stays on level 2 until the end of script