Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 API - Bug in WHERE clause, when filtering email1 field #9147

Open
csskevin opened this issue May 25, 2021 · 0 comments
Open

V8 API - Bug in WHERE clause, when filtering email1 field #9147

csskevin opened this issue May 25, 2021 · 0 comments
Labels
Area: API Issues & PRs related to all things regarding the API Area: Emails Issues & PRs related to all things regarding emails & email module Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Type: Bug Bugs within the core SuiteCRM codebase

Comments

@csskevin
Copy link

csskevin commented May 25, 2021

Hey,
there seems to be a bug in the V8 API in version 7.11.19, (I am not sure if these affects older versions as well, I just have tested it for that version), where the filter function for the email1 field doesn't work.
This applies to the comment I posted here: #8617 (comment)

Issue

By trying:
https://<suitecrm_url>/Api/V8/module/Accounts?filter[email1][eq]=<some_email>

Please note, that <suitecrm_url> and <some_email> are just placeholder!

I always get as response, and it doesn't matter if the email address exists or not:

{
  "meta": {
    "message": "Request was successful, but there is no result"
  },
  "data": []
}

After digging in the code a bit and debugging the query I found some interesting SQL query statement:

SELECT accounts.id FROM email_addresses JOIN email_addr_bean_rel ON email_addresses.id=email_addr_bean_rel.email_address_id JOIN accounts ON accounts.id=email_addr_bean_rel.bean_id where (email_addresses.email_address='<some_email>' AND accounts.deleted='0') AND accounts.deleted=1

Which is a bit odd, if you look closely at the WHERE clause, which says: (email_addresses.email_address='<some_email>' AND accounts.deleted='0') AND accounts.deleted=1
From then on, it made sense why the query always fails.

After further debugging I found this interesting line:

if ($deleted === 0) {
$whereAuto = '' . $bean->table_name . ' .deleted=0';
} else {
$whereAuto = '' . $bean->table_name . ' .deleted=1';
}

And the variable $deleted is defined as:

$deleted = $params->getDeleted();

The issue now is, that the value of $deleted is false and due value and type check $deleted === 0 it obviously fails, due 0 === false is false.

So changing this line to:

if (!$deleted) {
    $whereAuto = '' . $bean->table_name . ' .deleted=0';
} else {
    $whereAuto = '' . $bean->table_name . ' .deleted=1';
}

solves this issue.

@johnM2401 johnM2401 added Area: API Issues & PRs related to all things regarding the API Area: Emails Issues & PRs related to all things regarding emails & email module Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Type: Bug Bugs within the core SuiteCRM codebase labels May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: API Issues & PRs related to all things regarding the API Area: Emails Issues & PRs related to all things regarding emails & email module Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Type: Bug Bugs within the core SuiteCRM codebase
Projects
None yet
Development

No branches or pull requests

2 participants