mirror of
https://github.com/SuiteCRM/SuiteCRM.git
synced 2026-03-02 19:16:58 -05:00
Database Failures in Subpanels throughout SuiteCRM (MySQL Error) #4870
Labels
No labels
Area: API
Area: Campaigns
Area: Cases
Area: Clean Up
Area: Clean Up: Performance
Area: Dashlets
Area: Databases
Area: Developer Tools
Area: Elasticsearch
Area: Elasticsearch
Area: Emails
Area: Emails:Campaigns
Area: Emails:Cases
Area: Emails:Compose
Area: Emails:Config
Area: Emails:Templates
Area: Environment
Area: Installation
Area: Language
Area: Mobile
Area: Module
Area: PDFs
Area: PHP8
Area: Reports
Area: Studio
Area: Styling
Area: Upgrading
Area: Workflow
Area:Activity Stream
Area:Calls
Area:Import
Area:Projects
Area:Search
Area:Surveys
Area:Themes
Area:Users
Branch:Hotfix
Good First Issue
Hacktoberfest
Help Wanted
PR:Community Contribution
PR:Type:Enhancement
Priority:Critical
Priority:Important
Priority:Moderate
Severity: Major
Severity: Minor
Severity: Moderate
Status: Requires Code Review
Status: Requires Updates
Status: Stale
Status: Team Investigating
Status:Assessed
Status:Fix Proposed
Status:Needs Assessed
Status:Requires Automated Tests
Type: Bug
Type:Deprecated
Type:Discussion
Type:Duplicate
Type:Invalid
Type:Question
Type:Suggestion
Type:Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/SuiteCRM-SuiteCRM#4870
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pstevens71 on GitHub (Oct 12, 2022).
Issue
Database error in subpanels with the error: ERROR 1250 (42000): Table ‘…’ from one of the SELECTs cannot be used in global ORDER clause. The issue pertains to use the Table name in the sort clause. This seemed to work fine until today (Oct. 10. 2022). So must have been a recent update in mySQL that no longer permits this syntax. I was able to get the subpanel to display contacts again by sorting on a different column. Example below (screenshots) is in the Cases module and Contacts Subpanel. However, this issue is throughout SuiteCRM and not just this module, and not just contacts.


When I sort on "Accounts" it works:
Expected Behavior
The contact in the subpanel should display without error.
Actual Behavior
Contacts in subpanel display with database error.
```Wed Oct 12 14:08:16 2022 [16187][1][FATAL] Error retrieving Case list: Query Failed: (SELECT contacts.id , contacts.first_name , contacts.last_name , contacts.salutation , LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,'')))) as name, ' ' account_name , ' ' account_id , contacts.phone_work , contacts.assigned_user_id , 'contacts' panel_name FROM contacts LEFT JOIN contacts_cstm ON contacts.id = contacts_cstm.id_c INNER JOIN contacts_cases ON contacts.id=contacts_cases.contact_id AND contacts_cases.case_id='9e5568fd-3fd7-5130-0a83-6345f29aafeb' AND contacts_cases.deleted=0where contacts.deleted=0) ORDER BY contacts.last_name, contacts.first_name asc LIMIT 0,10: MySQL error 1250: Table 'contacts' from one of the SELECTs cannot be used in global ORDER clause ```
Possible Fix
As a work around, I can sort by another column to avoid the error.
The fix is to remove the table name from "sort by" I think, but this is throughout all the subpanels not sure where to start. the ORDERBY contacts.last_name I think is what's causing the problem and should be just ORDERBY last_name.
Steps to Reproduce
Context
This is a huge issue, I imagine affects every installation on MySQL 8.0.31
Your Environment
@SuiteBot commented on GitHub (Oct 12, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/mysql-error-1250-table-contacts-from-one-of-the-selects-cannot-be-used-in-global-order-clause/86551/12
@SuiteBot commented on GitHub (Oct 12, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/weird-behavior-sorting-on-subpanels/86554/5
@lefred commented on GitHub (Oct 13, 2022):
Hello,
I am working for MySQL, with 8.0.31, we have made some changes in the optimizer for a better handling of parenthesis to follow even better the SQL standards.
So in case of the following query:
Now the ORDER BY is related to the content of the query in the parenthesis and this can be used:
if the order by field is unique in the query, we just remove the table name reference like this:
if the column name is identical but from 2 different tables (like my first query), then you need to alias it or use the column's number like this :
or
Without the parenthesis it works as previously:
Cheers,
@lowbouncerate commented on GitHub (Oct 13, 2022):
Hi,
Where I can update the Query - I am not a Pro User of SuiteCRM
@lefred commented on GitHub (Oct 13, 2022):
I've submitted a bug in our system too.
@lowbouncerate commented on GitHub (Oct 13, 2022):
you can try to set both values as
'sort_order' => false,
'sort_by' => false,
it is working for me.
@iias12 commented on GitHub (Oct 13, 2022):
Where did you change these settings?
@lowbouncerate commented on GitHub (Oct 14, 2022):
I am using 7.10.x and we are using custom panels
custom/modules/Leads/Ext/Layoutdefs
@hbartel commented on GitHub (Oct 19, 2022):
Has anyone been able to trace down what file is building this SQL query?
The fix should be as simple as removing the outer ( ) from the query:
(SELECT ... contacts.deleted=0) ORDER BY ...
But I have not been able to determine what file is building the query.
@pgorod commented on GitHub (Oct 20, 2022):
You can ask PHP to give you a full stack trace on that error, this should be enough to determine where it's coming from.
@pstevens71 commented on GitHub (Oct 20, 2022):
I set level to ERROR and Enable stack trace to checked and it doesn't give me any further info. This is the output.....
Thu Oct 20 14:12:58 2022 [20457][1][FATAL] Error retrieving Case list: Query Failed: (SELECT contacts.id , contacts.first_name , contacts.last_name , contacts.salutation , LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,'')))) as name, ' ' account_name , ' ' account_id , contacts.phone_work , contacts.assigned_user_id , 'contacts' panel_name FROM contacts LEFT JOIN contacts_cstm ON contacts.id = contacts_cstm.id_c INNER JOIN contacts_cases ON contacts.id=contacts_cases.contact_id AND contacts_cases.case_id='6a66b4d6-34a3-ef97-0de0-634878effa1e' AND contacts_cases.deleted=0
where contacts.deleted=0) ORDER BY contacts.last_name, contacts.first_name asc LIMIT 0,10: MySQL error 1250: Table 'contacts' from one of the SELECTs cannot be used in global ORDER clause
Thu Oct 20 14:12:58 2022 [20457][1][FATAL] [ListView::processUnionBeans] . Database failure. Please refer to suitecrm.log for details.
Thu Oct 20 14:12:59 2022 [20457][1][ERROR] Unable to find relationship emails_email_templates
Thu Oct 20 14:12:59 2022 [20457][1][ERROR] Unable to find relationship emails_email_templates
Thu Oct 20 14:13:54 2022 [20629][1][FATAL] Mysqli_query failed.
Thu Oct 20 14:13:54 2022 [20629][1][FATAL] Error retrieving Case list: Query Failed: (SELECT contacts.id , contacts.first_name , contacts.last_name , contacts.salutation , LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,'')))) as name, ' ' account_name , ' ' account_id , contacts.phone_work , contacts.assigned_user_id , 'contacts' panel_name FROM contacts LEFT JOIN contacts_cstm ON contacts.id = contacts_cstm.id_c INNER JOIN contacts_cases ON contacts.id=contacts_cases.contact_id AND contacts_cases.case_id='6a66b4d6-34a3-ef97-0de0-634878effa1e' AND contacts_cases.deleted=0
where contacts.deleted=0) ORDER BY contacts.last_name, contacts.first_name asc LIMIT 0,10: MySQL error 1250: Table 'contacts' from one of the SELECTs cannot be used in global ORDER clause
Thu Oct 20 14:13:54 2022 [20629][1][FATAL] [ListView::processUnionBeans] . Database failure. Please refer to suitecrm.log for details.
There's nothing in the suitecrm.log
@lefred commented on GitHub (Oct 20, 2022):
I'm not a SuiteCRM developer (or even user), but to me it seems the stack trace is clear a refers to
github.com/salesagility/SuiteCRM@d57e91389d/include/ListView/ListView.php (L1077)@hbartel commented on GitHub (Oct 20, 2022):
Found it!
github.com/salesagility/SuiteCRM@7b6ac1bb78/data/SugarBean.php (L930)To fix comment out the line:
//$query = '(' . $query . ')';
@pstevens71 commented on GitHub (Oct 20, 2022):
Nice, I was trying to track that down too. I was in SugarBean.php too, didn't see that one. Great, I'm going to test!
@pstevens71 commented on GitHub (Oct 20, 2022):
I've tested and it seems to have fixed the issue in all modules.
@pstevens71 commented on GitHub (Oct 21, 2022):
After more testing, the fix above works except for "Products" It' s the same function in the error output. I'll have a look and see if I can find it related to products. Here's the error output for Products.
Fri Oct 21 14:00:26 2022 [8356][1][FATAL] Mysqli_query failed.
Fri Oct 21 14:00:26 2022 [8356][1][FATAL] Error retrieving AOS_Products list: Query Failed: (
SELECT * FROM (
SELECT
aos_quotes.*,
accounts.id AS account_id,
accounts.name AS billing_account,
Fri Oct 21 14:00:26 2022 [8356][1][FATAL] [ListView::processUnionBeans] . Database failure. Please refer to suitecrm.log for details.
@PepeImpulso commented on GitHub (Oct 21, 2022):
Works for me! I was starting to get desperate!
@SuiteBot commented on GitHub (Oct 27, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/upgrade-from-7-12-4-to-7-12-7-database-failure/86735/3
@gunnicom commented on GitHub (Oct 27, 2022):
Commenting the line seems more like a workaround than a fix to me. Just saying.
@hah100 commented on GitHub (Oct 27, 2022):
Products still gives the same error
@hbartel commented on GitHub (Oct 27, 2022):
The issue is that the SQL query is formatted incorrectly for MySQL 8.0.31. Removing the extra () in the query by commenting out the line directly fixes the issue. It is not a work around, it is a direct fix for the Contacts, Opportunities and Leads subpannels.
The products subpannel has the same issue, that the SQL query is formatted incorrectly for MySQL 8.0.31, but the query is being built by a different bit of code. For products we need to find where that query is being built and apply a similar fix.
@gunnicom commented on GitHub (Oct 27, 2022):
@hbartel Sorry I did not look correctly. You are right commenting this line would fix it. Just wonder what is the reason the braces are there initially?
@hbartel commented on GitHub (Oct 27, 2022):
I did more testing but I am not able to reproduce the issue that Hah100 and Pstevens71 are seeing with the products subpannel when line 930 is commented out.
One possibility is:
github.com/salesagility/SuiteCRM@7b6ac1bb78/data/SugarBean.php (L876)@pstevens71 commented on GitHub (Oct 27, 2022):
Nice! That solves my problem. I was all over that function and didn't see that line. I did this to test if that fixes it and it does...
@hah100 commented on GitHub (Oct 27, 2022):
Yess, great. Fixed. Thanks a lot for that!
@pstevens71 commented on GitHub (Oct 27, 2022):
OK so who knows how to setup a request to have these changes added to the code?
@hah100 commented on GitHub (Oct 27, 2022):
I guess the developers read this too?
@hbartel commented on GitHub (Oct 27, 2022):
I created a pull request for the proposed changes so that they can be reviewed.
@pstevens71 commented on GitHub (Oct 27, 2022):
Thanks @hbartel that's awesome. One of these days I have to learn how to do that!
@SuiteBot commented on GitHub (Nov 2, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/suitecrm-database-failure-after-assigning-role-management/86814/2
@SuiteBot commented on GitHub (Dec 6, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/target-list-error-message/42001/3
@SuiteBot commented on GitHub (Dec 14, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/after-moving-to-new-server-i-get-error/87287/6
@SuiteBot commented on GitHub (Dec 23, 2022):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/contact-database-failure-please-refer-to-suitecrm-log-for-details/87401/3
@pstevens71 commented on GitHub (Jan 10, 2023):
Also on line 930
comment out:
$query = '(' . $query . ')';
AND
line: 876 remove the brackets and quotations:
$final_query = '(' . $tmp_final_query . ')';
to
$final_query = $tmp_final_query;
Both changes are required to fix this issue.
@SuiteBot commented on GitHub (Jan 10, 2023):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/error-with-mssql-database/17514/4
@SuiteBot commented on GitHub (Apr 19, 2023):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/probleme-beim-einstellen-sicherheitsgruppen/88798/5
@chris001 commented on GitHub (Oct 27, 2023):
Fix not present in
7.14.1or8.4...@aurelien1980 commented on GitHub (Dec 6, 2023):
This fixes the error with mysql 8.
How come it is not released in SuiteCRM yet ?
@pgorod commented on GitHub (Dec 7, 2023):
The fix is in #9843
@SuiteBot commented on GitHub (Jan 7, 2024):
This issue has been mentioned on SuiteCRM. There might be relevant details there:
https://community.suitecrm.com/t/suitecrm-8-5-sql-errors-and-access-authorisation-errors/91456/2
@aurelien1980 commented on GitHub (Sep 6, 2024):
Problem remains in Suitecrm 7.14.5 and MySQL 8.0.35
Fix is working well:
line 878: $final_query = '(' . $tmp_final_query . ')'; change to $final_query = $tmp_final_query;
line 933: $query = '(' . $query . ')'; comment this line