Fatal error / incomplete form validation: Batch Data Entry for Contributions
Summary:
For Batch Data Entry of contributions, incomplete validation of the "Received" column value can lead to a fatal error and import of only a subset of batch entries.
Repro:
To reproduce on dmaster (currently "Powered by CiviCRM 5.70.alpha1"):
- Create a new Batch (Contributions > Batch Data Entry : New Data Entry Batch) containing 2 or more entries.
- For the first entry, fill all relevant fields with sensible data; important for repro: leave the Contribution Date date/time at its default value (or enter any other date/time value)
- For the second entry, fill all relevant fields with sensible data; important for repro: delete the date portion of the Contribution Date date/time value (but ensure there is a time component. E.g. NULL date, 10:20AM)
- Submit the form with "Validate and Process the Batch"
Expected (good) behavior:
- Form validation should notice that date component is empty in the second entry and alert the user that this is required.
- No entries are processed (no new contributions are created)
Actual (bad) behavior:
- Form is submitted without any validation errors.
- User observes fatal error: "Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred. DB Error: unknown error"
- The first entry is fully processed (a new contribution is created), but no subsequent entries are processed.
- The SQL error here is:
"INSERT INTO `civicrm_contribution` (`contact_id` , `financial_type_id` , `payment_instrument_id` , `receive_date` , `total_amount` , `fee_amount` , `net_amount` , `invoice_id` , `invoice_number` , `currency` , `source` , `contribution_status_id` , `check_number` , `campaign_id` , `tax_amount` ) VALUES ( 45968 , 48 , 4 , 10 , 200 , 0 , 200 , NULL , 'INV_11998' , 'USD' , '2023 EOY gift' , 1 , '297' , 95 , 0 ) [nativecode=1292 ** Incorrect datetime value: '10' for column `hft_civicrm`.`civicrm_contribution`.`receive_date` at row 1]"
(Note that the '10' in Incorrect datetime value: '10'
is the Hour part of the time component as submitted for the second entry.)
Proposed fix:
Form validation should ensure that a Date component is entered; a Time component without a Date component will result in the above misbehavior.