eileenmcnaughton / nz.co.fuzion.csvimport

Import to API using csv GUI
GNU Affero General Public License v3.0
8 stars 27 forks source link

Attempting to import Notes causes fatal error in Getunique generic api call #64

Open agileware-fj opened 1 year ago

agileware-fj commented 1 year ago

Steps to reproduce

  1. Have an import file for notes (nominally should include an ID resolution column and a note column, but we don't get that far)
  2. Start an import, use Entity Note
  3. Pick anything for ‘Which entity are you importing "Notes" to’ - Contacts is probably the most normal thing
  4. Add the upload file
  5. Try to start the import

Expected results

Load the mapping screen, allow to continue with import

Actual results

Fatal error:

PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in /var/www/html/wp-content/plugins/civicrm/civicrm/api/v3/Generic/Getunique.php:28

Stack trace:

0 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Provider/MagicFunctionProvider.php(85): civicrm_api3_generic_getunique(Array) 1 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(158): Civi\API\Provider\MagicFunctionProvider->invoke(Array) 2 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(81): Civi\API\Kernel->runRequest(Array) 3 /var/www/html/wp-content/plugins/civicrm/civicrm/api/api.php(133): Civi\API\Kernel->runSafe('civicrm_contact', 'getunique', Array) 4 /var/www/html/wp-content/plugins/civicrm/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Parser/Api.php(89): civicrm_api3('civicrm_contact', 'getunique', Array) 5 /var/www/html/wp-content/plugins/civicrm/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Parser/Api.php(116): CRM_Csvimport_Import_Parser_Api->getUniqueFields() 6 /var/www/html/wp-content/plugins/civicrm/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Parser/Api.php(58): CRM_Csvimport_Import_Parser_Api->getReferenceFields() 7 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Import/Parser.php(2012): CRM_Csvimport_Import_Parser_Api->setFieldMetadata() 8 /var/www/html/wp-content/plugins/civicrm/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Form/CSVImportFormTrait.php(33): CRM_Import_Parser->init() 9 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Import/Forms.php(772): CRM_Csvimport_Import_Form_MapField->getParser() 10 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Import/Forms.php(731): CRM_Import_Forms->getFields() 11 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Import/Form/MapField.php(69): CRM_Import_Forms->getAvailableFields() 12 /var/www/html/wp-content/plugins/civicrm/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Form/MapField.php(27): CRM_Import_Form_MapField->preProcess() 13 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Form.php(707): CRM_Csvimport_Import_Form_MapField->preProcess() 14 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Display.php(76): CRM_Core_Form->buildForm()

Comments

I believe the cause of this is that the getUniqueFields function is passing the entity table name to civicrm_api3 (line 4 of the stack trace), and the getunique implementation is then trying to load the entity name for DAO information, which returns null

As such I'm not sure if the problem is here or in the getUniqueFields implementation.

csvimport gets the values from the entity type from an APIv4 call, I believe, which are then used directly on the form; I think this could be adjusted for a workaround in the extension at least.

agileware-fj commented 1 year ago

Agileware ref is CIVICRM-2153

eileenmcnaughton commented 1 year ago

@agileware-fj I think getUniqueFields() is the right place to fix

andyburnsco commented 1 year ago

Also reproduced the same error