Answers.Body: <p>Based on comments this was a migration that had a leftover civicrm_uf_match record pointing to a non-existent user record.</p>
  <p>To also answer the last comment about how to avoid in future, one idea is a system status check that lists uf_match records that point to non-existent users or contacts.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-03T15:12:21.177Z
Answers.LastActivityDate: 2024-09-03T15:12:21.177Z
Answers.UserDisplayName: Demerit
Body: <p>I have a CiviCRM 5.76.2 installation on a WordPress 6.6.1 site (not on wordpress.com).  I just noticed that I have over 4,000 contacts in CiviCRM that have my email address (and nothing else) as contact info, and the number is growing every few minutes:</p>
  <pre><code>mysql&gt; select count(*) from civicrm_contact c where id in
     (select contact_id from civicrm_email where email='example@gmail.com');
  +----------+
  | count(*) |
  +----------+
  |     4226 |
  +----------+
  1 row in set (0.02 sec)
  
  mysql&gt; select count(*) from civicrm_contact c where id in
     (select contact_id from civicrm_email where email='example@gmail.com');
  +----------+
  | count(*) |
  +----------+
  |     4228 |
  +----------+
  1 row in set (0.03 sec)
  
  mysql&gt; select c.created_date, c.modified_date
     from civicrm_contact c, civicrm_email e
     where e.contact_id = c.id and email='example@gmail.com'
     order by c.modified_date desc limit 10;
  +---------------------+---------------------+
  | created_date        | modified_date       |
  +---------------------+---------------------+
  | 2024-09-02 17:51:02 | 2024-09-02 17:51:03 |
  | 2024-09-02 17:51:01 | 2024-09-02 17:51:01 |
  | 2024-09-02 17:50:40 | 2024-09-02 17:50:40 |
  | 2024-09-02 17:50:39 | 2024-09-02 17:50:39 |
  | 2024-09-02 17:50:38 | 2024-09-02 17:50:38 |
  | 2024-09-02 17:50:36 | 2024-09-02 17:50:37 |
  | 2024-09-02 17:48:39 | 2024-09-02 17:48:39 |
  | 2024-09-02 17:48:38 | 2024-09-02 17:48:38 |
  | 2024-09-02 17:48:37 | 2024-09-02 17:48:37 |
  | 2024-09-02 17:48:36 | 2024-09-02 17:48:36 |
  +---------------------+---------------------+
  10 rows in set (0.02 sec)
  </code></pre>
  <p>This is a very low-traffic site, there's definitely no other person inserting these users.  There must be an automated process doing this somewhere - but I can't figure out what it is.</p>
  <p>I only have two active Scheduled Jobs in CiviCRM, and they just run daily &amp; hourly:</p>
  <p><a href="https://i.sstatic.net/3i5nnGlD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3i5nnGlD.png" alt="scheduled jobs" /></a></p>
  <p>And my system <code>cron</code> only has the following jobs (this is the contents of the shell script that executes), run hourly:</p>
  <pre><code>~/private/bin/cv api job.execute --cwd=/home/example/www/wp
  
  BACKUP_DIR=~/private/backup/wordpress-site
  BIN_DIR=~/private/python-venv/bin
  
  cd ~/www/wp &amp;&amp; /usr/local/bin/wp db export - | gzip &gt; &quot;$BACKUP_DIR/full-db-$(date '+%FT%T%z').sql.gz&quot;
  &quot;$BIN_DIR/rotate-backups&quot; --hourly=10 --daily=7 --weekly=5 --monthly=12 --yearly=10 --include &quot;full-db-*&quot; &quot;$BACKUP_DIR&quot;
  
  cd ~/www &amp;&amp; tar -czf &quot;$BACKUP_DIR/files-$(date '+%FT%T%z').tar.gz&quot; wp
  &quot;$BIN_DIR/rotate-backups&quot; --hourly=10 --daily=7 --weekly=5 --monthly=12 --yearly=10 --include &quot;files-*&quot; &quot;$BACKUP_DIR&quot;
  </code></pre>
  <p>There are no logs at <code>/wp-admin/admin.php?page=CiviCRM&amp;q=civicrm%2Fadmin%2Flogviewer</code> that shed any light.</p>
  <p>What could possibly be doing this?  Can I turn on some extra logging to show what's creating contacts?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-02T22:20:47.590Z
Comments.Text: Check both (a) the civi dedupe rules (are they weird?) and (b) if there is some mismatch between the civi contact's email, the email stored in civicrm_uf_match, and the email for the associated wordpress user.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-02T22:23:29.123Z
Comments.Text: If that doesn't show anything you can add some code to an extension that implements hook_civicrm_post and log a backtrace with `CRM_Core_Error::backtrace('hello', true);` when the object is Contact and "op" is Create.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T02:50:57.693Z
Comments.Text: Hmm - so apparently the WordPress User ID is invalid, maybe?  When I click in the CiviCRM interface on the User ID, it takes me to https://example.org/wp-admin/user-edit.php?user_id=1046 and says "Invalid user ID."  Indeed, there's no user 1046 - I wonder if that's a holdover from it being a Drupal site.
Comments.UserDisplayName: Ken Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T02:54:25.800Z
Comments.Text: Yes so look in civicrm_uf_match. It probably has uf_id=1046 where contact_id = your contact. Try just updating the uf_id on that db row to match the wordpress id.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T02:54:29.317Z
Comments.Text: @Demerit is it okay to just do `UPDATE civicrm_uf_match SET uf_id=1 WHERE contact_id=102`?  Or does it need to be done programmatically to ensure consistency with other stuff?
Comments.UserDisplayName: Ken Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T02:54:54.897Z
Comments.Text: I think we posted at the same time. Yes exactly.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T02:57:37.747Z
Comments.Text: Awesome, I've made the change and I'll wait a bit to see whether the ghouls stop spawning.
Comments.UserDisplayName: Ken Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-03T04:12:13.670Z
Comments.Text: Okay, so I think this fixed it for me, no more new phantoms.  What's the best course of action to get this fixed?  I feel like having a dangling reference in `civicrm_uf_match` shouldn't cause thousands of contacts to get created, right?
Comments.UserDisplayName: Ken Williams
Tags: <contacts><debugging>
Title: Thousands of phantom contacts being created
ThreadText: # Thousands of phantom contacts being created
  
  (Asked by: username_0 on 2024-09-02)
  
  I have a CiviCRM 5.76.2 installation on a WordPress 6.6.1 site (not on wordpress.com).  I just noticed that I have over 4,000 contacts in CiviCRM that have my email address (and nothing else) as contact info, and the number is growing every few minutes:
  mysql> select count(*) from civicrm_contact c where id in
     (select contact_id from civicrm_email where email='example@gmail.com');
  +----------+
  | count(*) |
  +----------+
  |     4226 |
  +----------+
  1 row in set (0.02 sec)
  
  mysql> select count(*) from civicrm_contact c where id in
     (select contact_id from civicrm_email where email='example@gmail.com');
  +----------+
  | count(*) |
  +----------+
  |     4228 |
  +----------+
  1 row in set (0.03 sec)
  
  mysql> select c.created_date, c.modified_date
     from civicrm_contact c, civicrm_email e
     where e.contact_id = c.id and email='example@gmail.com'
     order by c.modified_date desc limit 10;
  +---------------------+---------------------+
  | created_date        | modified_date       |
  +---------------------+---------------------+
  | 2024-09-02 17:51:02 | 2024-09-02 17:51:03 |
  | 2024-09-02 17:51:01 | 2024-09-02 17:51:01 |
  | 2024-09-02 17:50:40 | 2024-09-02 17:50:40 |
  | 2024-09-02 17:50:39 | 2024-09-02 17:50:39 |
  | 2024-09-02 17:50:38 | 2024-09-02 17:50:38 |
  | 2024-09-02 17:50:36 | 2024-09-02 17:50:37 |
  | 2024-09-02 17:48:39 | 2024-09-02 17:48:39 |
  | 2024-09-02 17:48:38 | 2024-09-02 17:48:38 |
  | 2024-09-02 17:48:37 | 2024-09-02 17:48:37 |
  | 2024-09-02 17:48:36 | 2024-09-02 17:48:36 |
  +---------------------+---------------------+
  10 rows in set (0.02 sec)
  
  This is a very low-traffic site, there's definitely no other person inserting these users.  There must be an automated process doing this somewhere - but I can't figure out what it is.
  I only have two active Scheduled Jobs in CiviCRM, and they just run daily & hourly:
  
  And my system cron only has the following jobs (this is the contents of the shell script that executes), run hourly:
  ~/private/bin/cv api job.execute --cwd=/home/example/www/wp
  
  BACKUP_DIR=~/private/backup/wordpress-site
  BIN_DIR=~/private/python-venv/bin
  
  cd ~/www/wp && /usr/local/bin/wp db export - | gzip > "$BACKUP_DIR/full-db-$(date '+%FT%T%z').sql.gz"
  "$BIN_DIR/rotate-backups" --hourly=10 --daily=7 --weekly=5 --monthly=12 --yearly=10 --include "full-db-*" "$BACKUP_DIR"
  
  cd ~/www && tar -czf "$BACKUP_DIR/files-$(date '+%FT%T%z').tar.gz" wp
  "$BIN_DIR/rotate-backups" --hourly=10 --daily=7 --weekly=5 --monthly=12 --yearly=10 --include "files-*" "$BACKUP_DIR"
  
  There are no logs at /wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fadmin%2Flogviewer that shed any light.
  What could possibly be doing this?  Can I turn on some extra logging to show what's creating contacts?
  
  **Tags:** contacts, debugging
  
  > **Comments:**
  > **username_1**: Check both (a) the civi dedupe rules (are they weird?) and (b) if there is some mismatch between the civi contact's email, the email stored in civicrm_uf_match, and the email for the associated wordpress user.  
  > **username_1**: If that doesn't show anything you can add some code to an extension that implements hook_civicrm_post and log a backtrace with `CRM_Core_Error::backtrace('hello', true);` when the object is Contact and "op" is Create.  
  > **username_0**: Hmm - so apparently the WordPress User ID is invalid, maybe?  When I click in the CiviCRM interface on the User ID, it takes me to https://example.org/wp-admin/user-edit.php?user_id=1046 and says "Invalid user ID."  Indeed, there's no user 1046 - I wonder if that's a holdover from it being a Drupal site.  
  > **username_1**: Yes so look in civicrm_uf_match. It probably has uf_id=1046 where contact_id = your contact. Try just updating the uf_id on that db row to match the wordpress id.  
  > **username_0**: @username_1 is it okay to just do `UPDATE civicrm_uf_match SET uf_id=1 WHERE contact_id=102`?  Or does it need to be done programmatically to ensure consistency with other stuff?  
  > **username_1**: I think we posted at the same time. Yes exactly.  
  > **username_0**: Awesome, I've made the change and I'll wait a bit to see whether the ghouls stop spawning.  
  > **username_0**: Okay, so I think this fixed it for me, no more new phantoms.  What's the best course of action to get this fixed?  I feel like having a dangling reference in `civicrm_uf_match` shouldn't cause thousands of contacts to get created, right?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-09-03. Score: 2 | Accepted answer
  
  Based on comments this was a migration that had a leftover civicrm\_uf\_match record pointing to a non-existent user record.
  
  To also answer the last comment about how to avoid in future, one idea is a system status check that lists uf\_match records that point to non-existent users or contacts.
  
  
  ---
  
  