API call filtering contacts by email1 returns contacts with deleted mail addresses #4779

Open
opened 2026-02-20 16:23:48 -05:00 by deekerman · 5 comments
Owner

Originally created by @DaRealWorm on GitHub (Jun 2, 2022).

Issue

When making an API call to the V8 Json API for contacts filtering by email1 field eg [...]/V8/module/Contacts?filter[email1][eq]=test@example.com contacts are returned that do no currently have this address but had it in the past and is now deleted.
The resulting query is SELECT contacts.id FROM email_addresses JOIN email_addr_bean_rel ON email_addresses.id = email_addr_bean_rel.email_address_id JOIN contacts ON contacts.id = email_addr_bean_rel.bean_id where ((email_addresses.email_address = 'test@example.com') AND contacts.deleted = '0') AND contacts .deleted=0 LIMIT 0,20.
This will return all contacts that currently have or ever had a relationship to this e-mail address. Only deleted contacts are excluded but no deleted email_addr_bean_rels.

Expected Behavior

Only contacts currently having an active (deleted = 0) relationship to the e-mail address should be returned.

Actual Behavior

Contacts whose relationship to this address has been deleted will still be found and returned.

Possible Fix

Including and email_addr_bean_rel.deleted = 0 in the query.
Can be included in Api/V8/Service/ModuleService.php where the Email where clause is being constructed.

Steps to Reproduce

  1. enter e-mail address (eg. test@example.com) in contact
  2. remove address from contact
  3. query Json API [...]/V8/module/Contacts?filter[email1][eq]=test@example.com
  4. contact will be returned although it does not contain the address

Context

I was trying to find a contact by e-mail address and got one that obviously did not contain the searched address. After checking the query I found that the contact previously had the address but was removed later.

Your Environment

  • SuiteCRM 7.12.5
  • PHP 7.3.29
  • MySQL 5.7.36
  • Red Hat Enterprise Linux Server release 7.9
  • Postman v9.20.3
Originally created by @DaRealWorm on GitHub (Jun 2, 2022). <!--- Provide a general summary of the issue in the **Title** above --> <!--- Before you open an issue, please check if a similar issue already exists or has been closed before. ---> <!--- If you have discovered a security risk please report it by emailing security@suitecrm.com. This will be delivered to the product team who handle security issues. Please don't disclose security bugs publicly until they have been handled by the security team. ---> <!--- Please be aware that as of the 31st January 2022 we no longer support 7.10.x. New issues referring to 7.10.x will only be valid if applicable to 7.12.x and above. If your issue is still applicable in 7.12.x, please create the issue following the template below --> #### Issue <!--- Provide a more detailed introduction to the issue itself, and why you consider it to be a bug --> <!--- Ensure that all code ``` is surrounded ``` by triple back quotes. This can also be done over multiple lines --> When making an API call to the V8 Json API for contacts filtering by `email1` field eg `[...]/V8/module/Contacts?filter[email1][eq]=test@example.com` contacts are returned that do no currently have this address but had it in the past and is now deleted. The resulting query is `SELECT contacts.id FROM email_addresses JOIN email_addr_bean_rel ON email_addresses.id = email_addr_bean_rel.email_address_id JOIN contacts ON contacts.id = email_addr_bean_rel.bean_id where ((email_addresses.email_address = 'test@example.com') AND contacts.deleted = '0') AND contacts .deleted=0 LIMIT 0,20`. This will return all contacts that currently have or ever had a relationship to this e-mail address. Only deleted contacts are excluded but no deleted `email_addr_bean_rel`s. #### Expected Behavior <!--- Tell us what should happen --> Only contacts currently having an active (`deleted = 0`) relationship to the e-mail address should be returned. #### Actual Behavior <!--- Tell us what happens instead --> <!--- Also please check relevant logs (suitecrm.log, php error.log etc.) --> Contacts whose relationship to this address has been deleted will still be found and returned. #### Possible Fix <!--- Not obligatory, but suggest a fix or reason for the bug --> Including `and email_addr_bean_rel.deleted = 0` in the query. Can be included in `Api/V8/Service/ModuleService.php` where the _Email where clause_ is being constructed. #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. enter e-mail address (eg. _test@example.com_) in contact 2. remove address from contact 3. query Json API `[...]/V8/module/Contacts?filter[email1][eq]=test@example.com` 4. contact will be returned although it does not contain the address #### Context <!--- How has this bug affected you? What were you trying to accomplish? --> <!--- If you feel this should be a low/medium/high priority then please state so --> I was trying to find a contact by e-mail address and got one that obviously did not contain the searched address. After checking the query I found that the contact previously had the address but was removed later. #### Your Environment <!--- Include as many relevant details about the environment you experienced the bug in * SuiteCRM Version used: * Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): * Environment name and version (e.g. MySQL, PHP 7): * Operating System and version (e.g Ubuntu 16.04): --> - SuiteCRM 7.12.5 - PHP 7.3.29 - MySQL 5.7.36 - Red Hat Enterprise Linux Server release 7.9 - Postman v9.20.3
Author
Owner

@samus-aran commented on GitHub (Jul 6, 2022):

Seems fairly logical the fix. I dunno if this has any play in the relationship between this bug and theirs https://github.com/salesagility/SuiteCRM/issues/9147

@samus-aran commented on GitHub (Jul 6, 2022): Seems fairly logical the fix. I dunno if this has any play in the relationship between this bug and theirs https://github.com/salesagility/SuiteCRM/issues/9147
Author
Owner

@krzaychoos commented on GitHub (Jul 1, 2024):

Unfortunately, their bug #9147 does not resolve Contacts issue. Contacts with deleted email addresses are still found via API V8 queries. Has anyone found a solution to this problem?

@krzaychoos commented on GitHub (Jul 1, 2024): Unfortunately, their bug #9147 does not resolve Contacts issue. Contacts with deleted email addresses are still found via API V8 queries. Has anyone found a solution to this problem?
Author
Owner

@SuiteBot commented on GitHub (Jul 2, 2024):

This issue has been mentioned on SuiteCRM. There might be relevant details there:

https://community.suitecrm.com/t/api-returning-duplicate-records-on-email1-filter/88399/8

@SuiteBot commented on GitHub (Jul 2, 2024): This issue has been mentioned on **SuiteCRM**. There might be relevant details there: https://community.suitecrm.com/t/api-returning-duplicate-records-on-email1-filter/88399/8
Author
Owner

@krzaychoos commented on GitHub (Jul 2, 2024):

Exactly! THX!

@krzaychoos commented on GitHub (Jul 2, 2024): Exactly! THX!
Author
Owner

@chris001 commented on GitHub (Jul 4, 2024):

Would someone like to make a PR to fix this issue, from the fixed SQL provided in this reply to the forum post?:
https://community.suitecrm.com/t/api-returning-duplicate-records-on-email1-filter/88399/4

@chris001 commented on GitHub (Jul 4, 2024): Would someone like to make a PR to fix this issue, from the fixed SQL provided in this reply to the forum post?: https://community.suitecrm.com/t/api-returning-duplicate-records-on-email1-filter/88399/4
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4779
No description provided.