Answers.Body: <p>Here's how I found what was causing the rollback:</p>
  
  <ol>
  <li>Grepped the codebase to find that CRM_Core_Transaction::rollback() is where a transaction is marked for rollback; there may be any number of good reasons to do this, for example, when using the <a href="https://docs.civicrm.org/dev/en/latest/api/changes/#460-added-force_rollback-option" rel="nofollow noreferrer">api parameter 'force_rollback'</a></li>
  <li>Used xdebug with my IDE (netbeans) to get the execution backtrace from this point in the code, trying to find where and why it was called.</li>
  <li>Following that backtrace, I finally noticed that on this Joomla site, the Joomla plugin CiviCRM Group Sync was what made the api call for which this transaction was marked for rollback.</li>
  </ol>
  
  <p>Other notes:</p>
  
  <ul>
  <li>I'm not 100% confident this is a bug in the "CiviCRM Group Sync" plugin, because I've been unable to create reproduction steps, e.g., I could not create a contact and cause it to have this bad behavior.</li>
  <li>The workaround was to temporarily disable the plugin, then make any change to the contact, then re-enable the plugin. Users can now make edits to this contact as usual, without this bad behavior.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-04T17:47:10.737Z
Answers.LastActivityDate: 2018-10-04T17:47:10.737Z
Answers.UserDisplayName: TwoMice
Answers.Body: <p>No errors of any kind, it's just when you get back to contact summary, the data hasn't changed? Strange if that's the case, you'd expect an exception to be thrown.</p>
  
  <p>Are those queries you posted the full list? Have you done a side by side comparison of all queries?</p>
  
  <p>It looks like there are several methods in /CRM/Core/Transaction.php that execute a rollback. </p>
  
  <p>Those may be places that you could run var_dump(debug_backtrace()) and look for differences, write it to a file if you have to.</p>
  
  <p>Another thing to try would be to copy all the sql statements, and run them outside of civi, like in mysql directly, or a mysql client, and see if you get an error message from that.</p>
  
  <p>Your not getting anything about database locks in a log are you?
  <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-detection.html" rel="nofollow noreferrer">https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-detection.html</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T23:12:39.523Z
Answers.LastActivityDate: 2018-05-11T23:33:54.297Z
Answers.LastEditDate: 2018-05-11T23:33:54.297Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>I have a few contacts in CiviCRM 4.7.27 for which changes in the "edit contact" form are not saving. The update queries are being sent to MySQL correctly, but they're in a transaction which is being being ended by a ROLLBACK statement, which obviously undoes the changes.</p>
  
  <p>For all other contacts, changes save just fine, with no ROLLBACK.</p>
  
  <p>Example queries from a single "Save" form submission:</p>
  
  <pre><code>UPDATE  civicrm_contact  SET contact_type = 'Individual' , contact_sub_type = NULL , sort_name = 'jones, jennifer' , display_name = 'jennifer jones' , first_name = 'jennifer'   WHERE (  civicrm_contact.id = 3198 );
  UPDATE  civicrm_uf_match  SET domain_id = 1 , uf_id = 6839 , uf_name = 'jnphillips_22@msn.com' , contact_id = 3198   WHERE (  civicrm_uf_match.id = 2754 );
  UPDATE civicrm_group g SET    cache_date = NULL, refresh_date = NULL WHERE  g.cache_date &lt;= '20180503151700';
  UPDATE civicrm_setting SET value = 'LnnjD1Un' WHERE name='navigation' AND contact_id IS NOT NULL;
  UPDATE civicrm_contact SET  email_greeting_custom = NULL , email_greeting_display = 'Dear jennifer', postal_greeting_custom = NULL , postal_greeting_display = 'Dear jennifer', addressee_custom = NULL , addressee_display = 'jennifer jones' WHERE id = 3198;
  ... (and lots of delete/insert on civicrm cache tables.)
  </code></pre>
  
  <p>How can I track down the source and cause of this ROLLBACK statement?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-07T04:46:39.280Z
Comments.Text: Is there a common pattern between contacts that work and those that don't? Can you create a new contact and step by step duplicate the information that is in another contact until it no longer saves?
Comments.UserDisplayName: Luke Stewart
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-11T23:25:45.317Z
Comments.Text: TwoMice you always have the most fun puzzles. This would be a good one for "Bring your problem" day at the Civi MeetUp.
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-11T23:27:51.993Z
Comments.Text: hit me up on mattermost if you want to bounce ideas
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-11T23:32:52.660Z
Comments.Text: Using a particular MySQL flavor like MariaDB or Percona? Version?
Comments.UserDisplayName: jackrabbithanna
Tags: <mysql><debugging><sql>
Title: What could trigger a transaction rollback on contact save?
ThreadText: # What could trigger a transaction rollback on contact save?
  
  (Asked by: username_0 on 2018-05-03)
  
  I have a few contacts in CiviCRM 4.7.27 for which changes in the "edit contact" form are not saving. The update queries are being sent to MySQL correctly, but they're in a transaction which is being being ended by a ROLLBACK statement, which obviously undoes the changes.
  
  For all other contacts, changes save just fine, with no ROLLBACK.
  
  Example queries from a single "Save" form submission:
  
  ```
  UPDATE  civicrm_contact  SET contact_type = 'Individual' , contact_sub_type = NULL , sort_name = 'jones, jennifer' , display_name = 'jennifer jones' , first_name = 'jennifer'   WHERE (  civicrm_contact.id = 3198 );
  UPDATE  civicrm_uf_match  SET domain_id = 1 , uf_id = 6839 , uf_name = 'jnphillips_22@msn.com' , contact_id = 3198   WHERE (  civicrm_uf_match.id = 2754 );
  UPDATE civicrm_group g SET    cache_date = NULL, refresh_date = NULL WHERE  g.cache_date <= '20180503151700';
  UPDATE civicrm_setting SET value = 'LnnjD1Un' WHERE name='navigation' AND contact_id IS NOT NULL;
  UPDATE civicrm_contact SET  email_greeting_custom = NULL , email_greeting_display = 'Dear jennifer', postal_greeting_custom = NULL , postal_greeting_display = 'Dear jennifer', addressee_custom = NULL , addressee_display = 'jennifer jones' WHERE id = 3198;
  ... (and lots of delete/insert on civicrm cache tables.)
  
  ```
  
  How can I track down the source and cause of this ROLLBACK statement?
  
  **Tags:** mysql, debugging, sql
  
  > **Comments:**
  > **username_1**: Is there a common pattern between contacts that work and those that don't? Can you create a new contact and step by step duplicate the information that is in another contact until it no longer saves?  
  > **username_2**: username_0 you always have the most fun puzzles. This would be a good one for "Bring your problem" day at the Civi MeetUp.  
  > **username_2**: hit me up on mattermost if you want to bounce ideas  
  > **username_2**: Using a particular MySQL flavor like MariaDB or Percona? Version?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-10-04. Score: 0 | Accepted answer
  
  Here's how I found what was causing the rollback:
  
  1. Grepped the codebase to find that CRM\_Core\_Transaction::rollback() is where a transaction is marked for rollback; there may be any number of good reasons to do this, for example, when using the [api parameter 'force\_rollback'](https://docs.civicrm.org/dev/en/latest/api/changes/#460-added-force_rollback-option)
  2. Used xdebug with my IDE (netbeans) to get the execution backtrace from this point in the code, trying to find where and why it was called.
  3. Following that backtrace, I finally noticed that on this Joomla site, the Joomla plugin CiviCRM Group Sync was what made the api call for which this transaction was marked for rollback.
  
  Other notes:
  
  * I'm not 100% confident this is a bug in the "CiviCRM Group Sync" plugin, because I've been unable to create reproduction steps, e.g., I could not create a contact and cause it to have this bad behavior.
  * The workaround was to temporarily disable the plugin, then make any change to the contact, then re-enable the plugin. Users can now make edits to this contact as usual, without this bad behavior.
  
  
  ---
  
  ### Answer by username_2 on 2018-05-11. Score: 0
  
  No errors of any kind, it's just when you get back to contact summary, the data hasn't changed? Strange if that's the case, you'd expect an exception to be thrown.
  
  Are those queries you posted the full list? Have you done a side by side comparison of all queries?
  
  It looks like there are several methods in /CRM/Core/Transaction.php that execute a rollback.
  
  Those may be places that you could run var\_dump(debug\_backtrace()) and look for differences, write it to a file if you have to.
  
  Another thing to try would be to copy all the sql statements, and run them outside of civi, like in mysql directly, or a mysql client, and see if you get an error message from that.
  
  Your not getting anything about database locks in a log are you?
  <https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-detection.html>
  
  
  ---
  
  