CiviCRM CRM_Financial_BAO_Order/getPriceSetID sometimes returns NULL and causes PHP Fatal error, sometimes frequently - possibly a cache or post upgrade issue
CiviCRM CRM_Financial_BAO_Order/getPriceSetID sometimes returns NULL and causes PHP Fatal error.
PHP message: PHP Fatal error: Uncaught TypeError: CRM_Financial_BAO_Order::getPriceSetID(): Return value must be of type int, null returned in /www/civicrm.org/public_html/wp-content/plugins/civicrm/civicrm/CRM/Financial/BAO/Order.php:474
Steps to maybe reproduce
- Set up a Contribution Page with a Price Set.
- Accept credit card or pay later option.
- Perform a back end Contribution and override the Amount, enter a different amount to that available in the Price Set.
- Select the option to Send Contribution Receipt to the Contact
- Submit the back end Contribution with payment
- PHP Fatal error may be thrown.
Step debugging, it appears that that Priceset ID is retrieved multiple times and when the error occurs, it is when the Message Template, Contributions - Receipt (off-line) is being composed.
An error of type E_ERROR was caused in line 462 of the file /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/CRM/Financial/BAO/Order.php. Error message: Uncaught TypeError: Return value of CRM_Financial_BAO_Order::getPriceSetID() must be of the type int, null returned in /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/CRM/Financial/BAO/Order.php:462
Stack trace:
#0 /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/CRM/Financial/BAO/Order.php(677): CRM_Financial_BAO_Order->getPriceSetID()
#1 /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/CRM/Contribute/WorkflowMessage/ContributionTrait.php(111): CRM_Financial_BAO_Order->getPriceSetMetadata()
#2 /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php(125): CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt->getIsShowLineItems()
#3 /var/www/australia.org.au/httpdocs/wp-content/plugins/civicrm/civicrm/Civi/WorkflowMessage/WorkflowMessage.php(132): Civi\WorkflowMessage\GenericWorkflowMessage->export()
#4 /var/www/australia.org.au/httpdocs/wp-content/plugins/civic...
Environment:
- PHP 8.2
- CiviCRM 5.72.3
Notes: It's hard to reproduce this problem and it occurs most randomly. At this stage, we think it's cache related. Most recently the problem occurred consistently post a CiviCRM upgrade and then just started working (ie. error went away).
We have added a special check to log and throw an exception rather than revert to the PHP Fatal error, see https://github.com/civicrm/civicrm-core/commit/e24238de20330234f58bf88882b459e014feadd0
Reporting it here just in case others have experienced this issue.
Agileware Ref: CIVICRM-2250