Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-21089

Fatal error on "Interview Respondents"

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.7.23
    • Fix Version/s: 4.7.25
    • Component/s: CiviCampaign
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      No
    • Acceptance Criteria:
      Go to Campaigns » Interview Respondents and see the expected result instead of a fatal error.

      Description

      While doing PR review for CRM-21063, I found that "Interview Respondents" for surveys generates a fatal error:

      Aug 21 14:07:26  [info] $Fatal Error Details = Array
      (
          [callback] => Array
              (   
                  [0] => CRM_Core_Error
                  [1] => handle
              )
          
          [code] => -19
          [message] => DB Error: no such field
      {{    [mode] => 16 }}
          [debug_info] => SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, contact_a.display_name as `display_name`, civicrm_address.id as address_id, civicrm_address.street_address as `street_address`, civicrm_address.street_number as `street_number`, civicrm_address.street_name as `street_name`, civicrm_address.street_unit as `street_unit`, civicrm_address.city as `city`, civicrm_address.postal_code as `postal_code`, civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_activity_target.contact_id as survey_activity_target_contact_id, civicrm_activity_target.id as survey_activity_target_id, civicrm_activity.id as survey_activity_id, civicrm_activity_assignment.id as survey_interviewer_id, civicrm_survey.id as campaign_survey_id, civicrm_campaign.id as campaign_id  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1) LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)  INNER JOIN civicrm_activity_contact civicrm_activity_target
         ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = 3)  INNER JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
      {{                                 AND civicrm_activity.activity_type_id IN (29,32,30,28,31) ) }}
      INNER JOIN  civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
      civicrm_activity_assignment.record_type_id = 1 )  INNER JOIN civicrm_survey ON ( civicrm_survey.id = civicrm_activity.source_record_id )  LEFT JOIN civicrm_website ON contact_a.id = civicrm_website.contact_id  WHERE  ( contact_a.contact_type IN ("Individual") AND civicrm_activity.source_record_id = 1 AND civicrm_survey.id = 1 AND civicrm_activity_assignment.contact_id = 202 AND civicrm_activity.status_id = 1 AND (civicrm_activity.is_deleted = 0 OR civicrm_activity.is_deleted IS NULL) )  AND (contact_a.is_deleted = 0)    ORDER BY `contact_a`.`sort_name` asc, `contact_a`.`id`  LIMIT 0, 50  [nativecode=1054 ** Unknown column 'civicrm_campaign.id' in 'field list']
          [type] => DB_Error
          [user_info] => SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, contact_a.display_name as `display_name`, civicrm_address.id as address_id, civicrm_address.street_address as `street_address`, civicrm_address.street_number as `street_number`, civicrm_address.street_name as `street_name`, civicrm_address.street_unit as `street_unit`, civicrm_address.city as `city`, civicrm_address.postal_code as `postal_code`, civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_activity_target.contact_id as survey_activity_target_contact_id, civicrm_activity_target.id as survey_activity_target_id, civicrm_activity.id as survey_activity_id, civicrm_activity_assignment.id as survey_interviewer_id, civicrm_survey.id as campaign_survey_id, civicrm_campaign.id as campaign_id  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1) LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)  INNER JOIN civicrm_activity_contact civicrm_activity_target
         ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = 3)  INNER JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
      {{                                 AND civicrm_activity.activity_type_id IN (29,32,30,28,31) ) }}
      INNER JOIN  civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
      civicrm_activity_assignment.record_type_id = 1 )  INNER JOIN civicrm_survey ON ( civicrm_survey.id = civicrm_activity.source_record_id )  LEFT JOIN civicrm_website ON contact_a.id = civicrm_website.contact_id  WHERE  ( contact_a.contact_type IN ("Individual") AND civicrm_activity.source_record_id = 1 AND civicrm_survey.id = 1 AND civicrm_activity_assignment.contact_id = 202 AND civicrm_activity.status_id = 1 AND (civicrm_activity.is_deleted = 0 OR civicrm_activity.is_deleted IS NULL) )  AND (contact_a.is_deleted = 0)    ORDER BY `contact_a`.`sort_name` asc, `contact_a`.`id`  LIMIT 0, 50  [nativecode=1054 ** Unknown column 'civicrm_campaign.id' in 'field list']
          [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, contact_a.display_name as `display_name`, civicrm_address.id as address_id, civicrm_address.street_address as `street_address`, civicrm_address.street_number as `street_number`, civicrm_address.street_name as `street_name`, civicrm_address.street_unit as `street_unit`, civicrm_address.city as `city`, civicrm_address.postal_code as `postal_code`, civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_activity_target.contact_id as survey_activity_target_contact_id, civicrm_activity_target.id as survey_activity_target_id, civicrm_activity.id as survey_activity_id, civicrm_activity_assignment.id as survey_interviewer_id, civicrm_survey.id as campaign_survey_id, civicrm_campaign.id as campaign_id  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1) LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)  INNER JOIN civicrm_activity_contact civicrm_activity_target
         ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = 3)  INNER JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
      {{                                 AND civicrm_activity.activity_type_id IN (29,32,30,28,31) ) }}
      INNER JOIN  civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
      civicrm_activity_assignment.record_type_id = 1 )  INNER JOIN civicrm_survey ON ( civicrm_survey.id = civicrm_activity.source_record_id )  LEFT JOIN civicrm_website ON contact_a.id = civicrm_website.contact_id  WHERE  ( contact_a.contact_type IN ("Individual") AND civicrm_activity.source_record_id = 1 AND civicrm_survey.id = 1 AND civicrm_activity_assignment.contact_id = 202 AND civicrm_activity.status_id = 1 AND (civicrm_activity.is_deleted = 0 OR civicrm_activity.is_deleted IS NULL) )  AND (contact_a.is_deleted = 0)    ORDER BY `contact_a`.`sort_name` asc, `contact_a`.`id`  LIMIT 0, 50  [nativecode=1054 ** Unknown column 'civicrm_campaign.id' in 'field list']"]
      )

      Aug 21 14:07:26  [info] $backTrace = #0 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Error.php(229): CRM_Core_Error::backtrace("backTrace", TRUE)
      #1 [internal function](): CRM_Core_Error::handle(Object(DB_Error))
      #2 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/PEAR.php(921): call_user_func((Array:2), Object(DB_Error))
      #3 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB.php(985): PEAR_Error->__construct("DB Error: no such field", -19, 16, (Array:2), "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #4 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/PEAR.php(575): DB_Error->__construct(-19, 16, (Array:2), "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #5 [internal function](): PEAR->_raiseError(Object(DB_mysqli), NULL, -19, NULL, NULL, "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...", "DB_Error", TRUE)
      #6 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/PEAR.php(224): call_user_func_array((Array:2), (Array:8))
      #7 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->__call("raiseError", (Array:7))
      #8 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -19, NULL, NULL, "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...", "DB_Error", TRUE)
      #9 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-19, NULL, NULL, NULL, "1054 ** Unknown column 'civicrm_campaign.id' in 'field list'")
      #10 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/mysqli.php(403): DB_mysqli->mysqliRaiseError()
      #11 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysqli->simpleQuery("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #12 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/DataObject.php(2446): DB_common->query("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #13 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/DB/DataObject.php(1635): DB_DataObject->_query("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #14 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/DAO.php(362): DB_DataObject->query("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #15 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/DAO.php(1331): CRM_Core_DAO->query("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...", TRUE)
      #16 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Contact/BAO/Query.php(4876): CRM_Core_DAO::executeQuery("SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, ...")
      #17 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Campaign/Selector/Search.php(241): CRM_Contact_BAO_Query->searchQuery(0, 50, Object(CRM_Utils_Sort), FALSE, FALSE, FALSE, FALSE, FALSE, NULL, NULL, NULL)
      #18 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Selector/Controller.php(420): CRM_Campaign_Selector_Search->getRows(4, 0, 50, Object(CRM_Utils_Sort), 1, NULL)
      #19 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Selector/Controller.php(340): CRM_Core_Selector_Controller->getRows(Object(CRM_Core_Selector_Controller))
      #20 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Campaign/Form/Search.php(323): CRM_Core_Selector_Controller->run()
      #21 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Campaign/Form/Search.php(125): CRM_Campaign_Form_Search->postProcess()
      #22 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Form.php(543): CRM_Campaign_Form_Search->preProcess()
      #23 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Display.php(92): CRM_Core_Form->buildForm()
      #24 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Display->perform(Object(CRM_Campaign_Form_Search), "display")
      #25 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Campaign_Form_Search), "display")
      #26 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Controller.php(351): HTML_QuickForm_Page->handle("display")
      #27 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Invoke.php(309): CRM_Core_Controller->run((Array:3), NULL)
      #28 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:15))
      #29 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:3))
      #30 /home/jon/local/civicrm-buildkit/build/dmaster/sites/all/modules/civicrm/drupal/civicrm.module(448): CRM_Core_Invoke::invoke((Array:3))
      #31 [internal function](): civicrm_invoke("survey", "search")
      #32 /home/jon/local/civicrm-buildkit/build/dmaster/includes/menu.inc(527): call_user_func_array("civicrm_invoke", (Array:2))
      #33 /home/jon/local/civicrm-buildkit/build/dmaster/index.php(21): menu_execute_active_handler()
      #34 {main}
      {{}}

      Because campaign_id is present in many different tables as a foreign key, CRM_Contact_BAO_Query::fromClause() must include a conditional to properly build the SQL from clause.  No such conditional exists for surveys.

      I presume that this worked at some point, so this is probably a result of untested refactoring.

      PR incoming.

       

      To replicate on the demo server:

      • Create at least one survey.
      • Go to Campaigns » Interview Respondents.  Observe the fatal error.

       

        Attachments

          Activity

            People

            • Assignee:
              palantejon Jon K Goldberg
              Reporter:
              palantejon Jon K Goldberg
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: