This one came up again for me so I set up some tracing. The error comes when the completetransaction api call tries to create a EntityFinancialTrxn, but there's no entity id. This is now with CiviCRM ver 5.49.5, CiviDiscount3.8.7
Here's the argument to the entity create call, which gets triggered as part of the completetransaction api call.
[entity_table] => civicrm_financial_item
[financial_trxn_id] => 6745
[entity_id] =>
[amount] => 0
[version] => 3
I notice that in spite of the error, a valid pending contribution is created, and that it can be manually completed without error.
When I look at that successful manual completion and compare, I can see that the failed completetransaction is failing at the point where it should have already created an entry in civicrm_financial_trxn - it needs to do that so that there's an id that can go in the civicrm_entity_financial_trxn as the entity id.
Since these are empty/dummy 'financial transactions', I suspect some logic somewhere in the financial system that's deciding it doesn't need to add an empty financial transaction.
Taking a different approach, I tried commenting out the completetransaction call in the Confirm.php page and discovered it tries twice to complete it, both times with notes about this being a bit of a kludge for membership edge cases.
After commenting both out, the UX no longer reports the error, though the contribution remains incomplete in the backend.
Conclusion: the completetransaction api seems to be where this needs fixing.