On several sites (all currently running CiviCRM 5.58.1 but all having existed much longer) I have found contributions which have no line items -- that is, rows in civicrm_contribution
that have no corresponding rows in civicrm_line_item
.
Could this in any way be normal?
I'm unable to reproduce such a situation at will, except by manually deleting rows in civicrm_line_item
via API or SQL. It seems any contribution record will, by design, have at least one line_item, even if using a quick-config contribution instead of a visible price set, or if manually creating even a zero-dollar contribution in the back-end.
This situation leads to a fatal error ("Return value of CRM_Financial_BAO_Order::getPriceSetID() must be of the type int, null returned") when attempting to generate a PDF invoice with "Download Invoice" for the given contribution, apparently on the assumption that this situation is not expected by core code.
Question: Is there any reasonable way -- i.e. not a bug -- that CiviCRM could be creating this situation? If so, I can explore a bug report on the above-mentioned fatal error. If not, I'll need to investigate further how this situation is arising on various sites. (And if you want to check on your own sites and comment on your findings, I'm naturally curious about that too.)
For reference, this query identifies the number of contributions having no line items:
SELECT count(*)
FROM
civicrm_contribution ctr
left join civicrm_line_item li on li.contribution_id = ctr.id
where li.id is null;