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

Contact API doesn't return error with invalid greeting

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.3.5
    • Fix Version/s: 3.4.alpha
    • Component/s: CiviCRM API
    • Labels:
      None

      Description

      Passing an invalid greeting to the create/update contact API causes the API to return a string, rather than an error object. civicrm_error doesn't think a string is an error. This can be seen with the following snippet:
      $params = array ('household_name' => 'Test',
      'postal_greeting' =>'Dear Dr. Test',
      'contact_type' => 'Household'
      );
      $contact = &civicrm_contact_create( $params );
      if( civicrm_error( $contact) ) {
      echo "Error occured while creating household\n";
      } else {
      echo $contact['contact_id'] . "\n";
      }

      Which displays "I" (because the create call returns "Invalid postal greeting" rather than an array. The immediate cause of this is this code inside api/Contact.php:
      $error = _civicrm_greeting_format_params( $params );
      if ( $error['error_message'] )

      { return $error['error_message']; }

      Which should be:
      if (civicrm_error( $error, 'CRM_Core_Error')) {
      return $error;

      It's also annoying (I think) that civicrm_error returns false if you pass it something other than an array. The safer thing would be to fail unless you're sure it's success (rather than succeed unless you're sure it's an error). However, I don't know much about the internals so I can imagine that some functions are inconsistent and return objects on success and arrays on error.

        Attachments

          Activity

            People

            • Assignee:
              rajan Rajan P Mayekar
              Reporter:
              taleswapper Ken Vogel
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: