mirror of
https://github.com/SuiteCRM/SuiteCRM.git
synced 2026-03-02 19:16:58 -05:00
Database failure when filtering on relate field and exporting #4455
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#4455
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 @dtosun61 on GitHub (Dec 7, 2020).
Originally assigned to: @jack7anderson7 on GitHub.
Issue
When i add custom Target list filter to Target module, it is working good. But when i select all records from bulk action menu and export them, there is an error which is Database failure. But when i select records of first page and exports, it is working good.
Expected Behavior
It should be working as expected.
Actual Behavior
Possible Fix
Steps to Reproduce
Add the file:
custom/Extension/modules/Prospects/Ext/Vardefs/targetlistfilter.phpwith content:
<?php $dictionary['Prospect']['fields']['prospect_list_name'] = array ( 'name' => 'prospect_list_name', 'rname' => 'name', 'id_name' => 'prospect_list_id', 'vname' => 'LBL_PROSPECTLIST_NAME', 'type' => 'relate', 'link' => 'prospect_lists', 'table' => 'prospect_lists', 'isnull' => 'true', 'module' => 'ProspectLists', 'dbType' => 'char', 'len' => '255', 'source' => 'non-db', 'duplicate_merge'=> 'disabled', );Add the file:
custom/Extension/modules/Prospects/Ext/Language/en_us.targetlistfilter.phpwith content:
<?php $mod_strings['LBL_PROSPECTLIST_NAME'] = 'Target List:';Afterwards, do a Admin / Repair / Quick Repair and Rebuild

2. Open Studio, module Contacts / Layouts / Filter
The filter field Target List is now available in the Hidden list and can be added to the Quick Filter and the Advance Filter layout.
3. Open Target module and filter with "Target List" field
Select all results

Then export them via Bulk Action Menu


6.See result
Suitecrm log;
Mon Dec 7 17:52:06 2020 [30995][e433d2f0-c23e-3ad2-bd4d-5ee727929421][FATAL] Mysqli_query failed. Mon Dec 7 17:52:06 2020 [30995][e433d2f0-c23e-3ad2-bd4d-5ee727929421][FATAL] Error exporting Prospects: .SELECT prospects., email_addresses.email_address email_address, ‘’ email_addresses_non_primary, users.user_name as assigned_user_name ,prospects_cstm.jjwg_maps_geocode_status_c,prospects_cstm.jjwg_maps_lng_c,prospects_cstm.jjwg_maps_lat_c,prospects_cstm.target_tag_c,prospects_cstm.jjwg_maps_address_c FROM prospects LEFT JOIN users ON prospects.assigned_user_id=users.id LEFT JOIN email_addr_bean_rel on prospects.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module = ‘Prospects’ and email_addr_bean_rel.deleted = 0 and email_addr_bean_rel.primary_address = 1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id LEFT JOIN prospects_cstm ON prospects.id = prospects_cstm.id_c WHERE ((prospect_list_name like ‘15 ŞUBAT 2018 KONFERANS KATILIMCI LİSTESİ%’)) AND prospects.deleted=0 Query Failed: SELECT prospects., email_addresses.email_address email_address, ‘’ email_addresses_non_primary, users.user_name as assigned_user_name ,prospects_cstm.jjwg_maps_geocode_status_c,prospects_cstm.jjwg_maps_lng_c,prospects_cstm.jjwg_maps_lat_c,prospects_cstm.target_tag_c,prospects_cstm.jjwg_maps_address_c FROM prospects LEFT JOIN users ON prospects.assigned_user_id=users.id LEFT JOIN email_addr_bean_rel on prospects.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module = ‘Prospects’ and email_addr_bean_rel.deleted = 0 and email_addr_bean_rel.primary_address = 1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id LEFT JOIN prospects_cstm ON prospects.id = prospects_cstm.id_c WHERE ((prospect_list_name like ‘15 ŞUBAT 2018 KONFERANS KATILIMCI LİSTESİ%’)) AND prospects.deleted=0 : MySQL error 1054: Unknown column ‘prospect_list_name’ in ‘where clause’ Mon Dec 7 17:52:06 2020 [30995][e433d2f0-c23e-3ad2-bd4d-5ee727929421][FATAL] Exception handling in /var/www/sucrm/crm/include/MVC/Controller/SugarController.php:400 Mon Dec 7 17:52:06 2020 [30995][e433d2f0-c23e-3ad2-bd4d-5ee727929421][FATAL] Exception in Controller: Database failure. Please refer to suitecrm.log for details. Mon Dec 7 17:52:06 2020 [30995][e433d2f0-c23e-3ad2-bd4d-5ee727929421][FATAL] backtrace: #0 /var/www/sucrm/crm/include/database/DBManager.php(353): sugar_die(‘Database failur…’) #1 /var/www/sucrm/crm/include/database/DBManager.php(328): DBManager->registerError(‘Error exporting…’, ‘Error exporting…’, true) #2 /var/www/sucrm/crm/include/database/MysqliManager.php(179): DBManager->checkError(‘Error exporting…’, true) #3 /var/www/sucrm/crm/include/export_utils.php(194): MysqliManager->query(‘SELECT\n\t\t\t\t\tpro…’, true, ‘Error exporting…’) #4 /var/www/sucrm/crm/export.php(69): export(‘Prospects’) #5 /var/www/sucrm/crm/include/MVC/Controller/SugarController.php(1020): require_once(’/var/www/sucrm/…’) #6 /var/www/sucrm/crm/include/MVC/Controller/SugarController.php(468): SugarController->handleEntryPoint() #7 /var/www/sucrm/crm/include/MVC/Controller/SugarController.php(373): SugarController->process() #8 /var/www/sucrm/crm/include/MVC/SugarApplication.php(113): SugarController->execute() #9 /var/www/sucrm/crm/index.php(52): SugarApplication->execute() #10 {main}Context
Your Environment
@johnM2401 commented on GitHub (Dec 8, 2020):
Hey,
I've had a look, and it seems the CRM will have slightly different behaviour, depending on whether it is exporting records from one page, or exporting records across multiple pages.
When exporting from one page, it seems to use the record's ID's in the "where" clause.
ie:
When searching over multiple pages, it will use the fields as a filter.
In this case, it is trying to do:
It would be worth checking, but I would imagine the "prospect_list_name" column does not exist in the Database table for the customized module?
(ie, Targets/Contacts)
If not, that would explain why you are hitting this DB error.
When running the Quick Repair and Rebuild, were you prompted to Execute any SQL?
This should appear if the Vardefs are fine, and the field is not in the DB, as this updates the Database with the necessary Columns/Values, to accommodate the new field.
If not, it might be worth creating this as a Relate field via Studio, unless there is a reason you need it to be custom code?
If custom code is needed, it might still be worth creating a Relate field via Studio, as you could inspect the auto-created Vardefs to see if anything needs to be added.
@dtosun61 commented on GitHub (Dec 8, 2020):
Yes i know prospect_list_name doesn't exist in DB. But the Target list filter working well. I can exports first page good. And also if i select all records page by page, it is working good also and exports all records well.
If i make selection from selection menu and export them from bulk action menu, i couldn't export them. I couldn't understand behavior of selection?
When i create relate field, i couldn't see it on DB. Is it normal? I make Quick Repair and Rebuild.
I create relate field for Target module and add this field to Target module, it doesn't work also.

@dtosun61 commented on GitHub (Dec 8, 2020):
@johnM2401 if you want i can give you access to my crm. You can see the issue.
@johnM2401 commented on GitHub (Dec 10, 2020):
Hey, Thanks for your response!
Hmm,
I've created a Relate field in Studio between Targets<->Target Lists, and it seems to create an item in the Database's prospects_cstm table.
It appears as though the column is named "prospectlist_id_c", rather than what i'd named the field.
(So the Relate field must take the target module, and use this to name the Column in the DB.)
Does this appear in your module's _cstm table?
If not, i'm not too sure..
It might be worth resetting your file/folder permissions and running another Quick Repair & Rebuild.
You also mentioned that "it doesnt work also"
Would you be able to clarify this?
Do you mean that exporting, while filtering on this new Relate field, gives you a Database Failure error?
Or, do you mean something else?
It seems to work for myself
I'm able to export All pages when filtering by this new Relate Field
(As an aside, it may be worth also bringing this to the community forums, as you will reach a wider audience with this, which could very well prove helpful )
@JanSiero commented on GitHub (Dec 10, 2020):
Easier way to reproduce this issue (without the use of custom fields):
-> The filter result should only show "account2"
Error is caused by legacy code in the function "create_export_query". This function is derived from the base function SugarBean::create_export_query . In most cases, the derived functions can be deleted / commented out as it contains obsolete additional functionality that is already covered by the base function.
Derived functions are in the following files and should be checked. Either way, derived functions should call the base function SugarBean::create_export_query or SugarBean::create_new_list_query
include/SugarObjects/templates/company/Company.phpinclude/SugarObjects/templates/person/Person.phpmodules/ProjectTask/ProjectTask.phpmodules/ProspectLists/ProspectList.phpmodules/Opportunities/Opportunity.phpmodules/Notes/Note.phpmodules/Project/Project.phpmodules/Users/User.phpmodules/Accounts/Account.phpmodules/Contacts/Contact.phpmodules/Tasks/Task.phpmodules/Documents/Document.phpmodules/EmailMan/EmailMan.phpmodules/Bugs/Bug.phpmodules/Emails/Email.phpmodules/Calls/Call.phpmodules/Meetings/Meeting.phpmodules/Groups/Group.phpmodules/Campaigns/Campaign.phpmodules/Employees/Employee.php@dtosun61 commented on GitHub (Dec 11, 2020):
I comment out this function in the file
include/SugarObjects/templates/person/Person.phpFunction
public function create_export_query($order_by, $where, $relate_link_join = '')My problem is solved. I think this is a bug and should be important.
Thank you @JanSiero
@johnM2401 commented on GitHub (Dec 11, 2020):
Very much appreciated @JanSiero
I'm able to replicate quite easily with those steps.
I've marked this as a Critical Bug now, as it's a replicable DB Failure.
Also, thanks to @dursuntosun for your patience in this!
@JanSiero commented on GitHub (Dec 11, 2020):
Hi @johnM2401 ,
I'll try to supply a pull request on short term.
I suggest to change the title of this issue to: "Database failure when filtering on relate field and exporting"
@stlgaits commented on GitHub (Feb 8, 2022):
Hi, any updates regarding this bug & PR ?
@holdusback commented on GitHub (Feb 10, 2022):
I have this exact same error in the lastest version : 7.12.3
I filter account with a relative field in account.
So it's a relative field from account to account : accounts_accounts_2
Here is the log from the where statement of the SQL request :
where ((accounts.account_type in ('Beneficiaire') ) AND ( accounts_accounts_2_name like 'XXX XXXX%')) AND ( accounts.deleted IS NULL OR accounts.deleted=0 ): MySQL error 1054: Unknown column 'accounts_accounts_2_name' in 'where clause'
@SinergiaCRM commented on GitHub (May 4, 2022):
What are the updates on this issue? Are the latest referenced commits becoming a PR?
Thanks
@SinergiaCRM commented on GitHub (May 11, 2022):
We analyzed the issue with detail and we thought it might help here. These are the results:
We would like to emphasize the "Assign Security Group" and the "Print PDF" actions, that weren't mentioned in this issue
@samus-aran commented on GitHub (May 11, 2022):
@jack7anderson7 Just a quick mention 👋
@SinergiaCRM commented on GitHub (Oct 18, 2023):
Hi,
We consider this a very important Issue that it's still around.
Although not sure this commit was suppose to solve this issue:
github.com/jack7anderson7/SuiteCRM@3c34e9cdc5Any updates? @clemente-raposo @johnM2401 @jack7anderson7
Thanks
@JanSiero commented on GitHub (Oct 18, 2023):
Hi, the mentioned commit does not solve the issue.
To resolve this, the method create_new_list_query needs a serious rewriting and afterwards extensive testing, see my comment:
https://github.com/salesagility/SuiteCRM/pull/9006#issuecomment-793021347