One day I noticed my transactions dont accept a ActiveRecord::Rollback. I have such an example:
ActiveRecord::Base.transaction do
puts @shipment_list.status
@shipment_list.update(shipment_list_params)
raise ActiveRecord::Rollback
end
puts @shipment_list.status
CACHE (0.0ms) SELECT `shipment_lists`.* FROM `shipment_lists` WHERE `shipment_lists`.`id` = 24121 ORDER BY created_at DESC LIMIT 1 [["id", "24121"]]
(0.2ms) BEGIN
reserve
(1.3ms) SELECT MAX(`audits`.`version`) AS max_id FROM `audits` WHERE `audits`.`auditable_id` = 24121 AND `audits`.`auditable_type` = 'ShipmentList'
SQL (160.5ms) INSERT INTO `audits` (`action`, `auditable_id`, `auditable_type`, `audited_changes`, `created_at`, `remote_address`, `request_uuid`, `user_id`, `user_type`, `version`) VALUES ('update', 24121, 'ShipmentList', '---\nstatus:\n- reserve\n- 2\n', '2016-07-10 12:01:55', '127.0.0.1', 'efc5b6e7-c3f9-4b4a-a0fd-67651b2eeb20', 18, 'User', 19)
SQL (0.3ms) UPDATE `shipment_lists` SET `status` = 2, `updated_at` = '2016-07-10 12:01:55' WHERE `shipment_lists`.`id` = 24121
(0.2ms) ROLLBACK
bill
Where is the mistake? I really in a trouble.
Actually the problem was caused by myISAM mysql schema. Transactions rollback is not allowed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.