Creating a relationship fails for an organization contact which has NULL values in start/end/join fields of a membership
When creating a relationship between an Individual and an Organizational contact, the relationship fails to be created and throws the following error if the Organizational contact record has a membership with NULL values in the start/end/join fields, such as might happen if a payment failed and the membership was created in a "Pending" state:
unknown relationship create error The membership cannot be saved because the status cannot be calculated for start_date: null end_date null join_date null as at 2018-03-09 16:43:22
What's odd is that I wouldn't expect the relationships to be dependent on a membership object, but for some reason it is? I did some testing on a client's sandbox site and found that any membership with NULL start/end/join dates will cause a Relationship creation to fail. I found that deleting the membership with NULL dates fixes the issue i.e. allows the relationship to be created, as does simply adding dates to the membership in question.
Backtrace:
Mar 09 16:43:23 [info] $backTrace = #0 /var/www/example.org/htdocs/sites/all/modules/civicrm/CRM/Core/Error.php(456): CRM_Core_Error::backtrace("backTrace", TRUE) #1 /var/www/example.org/htdocs/sites/all/modules/civicrm/CRM/Core/Invoke.php(55): CRM_Core_Error::handleUnhandledException(Object(CRM_Core_Exception)) #2 /var/www/example.org/htdocs/sites/all/modules/civicrm/drupal/civicrm.module(345): CRM_Core_Invoke::invoke((Array:4)) #3 [internal function](): civicrm_invoke("contact", "view", "rel") #4 /var/www/example.org/htdocs/includes/menu.inc(350): call_user_func_array("civicrm_invoke", (Array:3)) #5 /var/www/example.org/htdocs/index.php(17): menu_execute_active_handler() #6 {main}
NB: I am unable to manually re-create this scenario on the demo site (I tried) as a start date is required when creating a membership.