2.1.0+, Transaction is rolled back on API Exception, causing data loss
- Form Processor 2.1.0-beta1 added a database transaction to
executeActions
method ofCivi\FormProcessor\Runner
- CiviCRM implements a handler in
Civi\API\Subscriber\TransactionSubscriber->OnApiException
that rolls back the transaction on thecivi.api.exception
event -
civi.api.exception
is dispatched whenever an API Exception occurs before it can be caught by the calling code - This means that any Actions relying on API Exception handling will result in the data already written by itself and any previous Action in the same Form Processor being lost.
- For example, in the “Subscribe/Unsubscribe from group” action:
-
Civi\ActionProvider\Action\Group\UpdateGroupSubscriptions
tries to “delete”GroupContact
records. - These records might not already exist, so an exception is thrown and handled by the
TransactionSubscriber
as above. - No changes are saved to the database
- This happens any time a group that is not already subscribed to is not selected for subscription.
-
This can be verified using a CiviCRM instance with the sample data by importing this form and trying it out, selecting only a subset of groups:
Given that additional extensions may also implement actions that depending on caught Exception handling, the transaction in executeActions should possibly be changed to only work on an opt in basis.
Edited by Francis (Agileware)