Variable type error during import process
Overview
After upgrading to 5.22.0 importing data using dedupe rules is throwing a fatal PHP error and the import stops.
While this could be caused by a failure either in the data being imported or the specific (custom) dedupe rule being used, it seems like this is behaviour that either shouldn't happen at all, or that a more graceful error should be thrown informing the user of the cause of the problem.
Reproduction steps
- Click on Contacts -> Import Contacts.
- Import CSV file with circa 1000 rows of contact data.
- Select to update duplicate contacts.
- Select custom dedupe rule which identifies dupes based on a numeric custom field, name and email address (fields should be allowed to be empty).
- Click 'Continue' to reach confirmation screen.
- Start import.
Current behaviour
Fatal error thrown within in 2 or 3 seconds. PHP error log shows following error:
[15-Feb-2020 11:47:14 America/Toronto] PHP Fatal error: Uncaught TypeError: Argument 1 passed to civicrm_api3() must be of the type string, null given, called in /home/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Dedupe/BAO/Rule.php on line 62 and defined in /home/wordpress/wp-content/plugins/civicrm/civicrm/api/api.php:84
Stack trace:
#0 /home/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Dedupe/BAO/Rule.php(62): civicrm_api3(NULL, 'getfields', Array)
#1 /home/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Dedupe/BAO/RuleGroup.php(172): CRM_Dedupe_BAO_Rule->sql()
#2 /home/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Dedupe/BAO/RuleGroup.php(190): CRM_Dedupe_BAO_RuleGroup->tableQuery()
#3 /home/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Dedupe/Finder.php(127): CRM_Dedupe_BAO_RuleGroup->fillTable()
#4 /home/wordpress/wp-conten in /home/wordpress/wp-content/plugins/civicrm/civicrm/api/api.php on line 84
Expected behaviour
Contact data should import succesfully
Environment information
- Browser: Firefox 59.0.1/Chrome 78.0.3904/Safari 13
- CiviCRM: 5.22.0
- PHP: 7.3
- CMS: WordPress 5.3.2
- Database: MySQL 5.7.29
- Web Server: Apache 2.4.18
Comments
_ In order to complete the import I hacked civicrm/civicrm/CRM/Dedupe/BAO/Rule.php in the following way as a temporary workaround: _
At Line 61:
$entity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($this->rule_table));
// Start of hack:
if ($entity === NULL){
return;
}
//End of hack
$fields = civicrm_api3($entity, 'getfields', ['action' => 'create'])['values'];
This prevents api3 being called with a null value. However I doubt this is a good way to address the problem, and will obviously be overwritten by future updates.