Creating new node entity during presave of another node entity causes SQL Exception sometimes

We have a Donation Record Content type and a Donor content type for a Blood Bank management drupal application. A donor can have any number of donation record.

The system does not explicitly require creating a donor record prior to creating a donation record. It creates a donor record during presave of donation record if the donor reference is not provided in the URL. The system gets the reference from the created donor during presave and updates it in the donation record. Hence we now have a donor with a donation record while the user is saving a donation record.

The problem is that new donor record does not get created all the time. We get SQL Exception: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT savepoint_1 does not exist.

Is there any other way to create the donor so that this problem does not occur or am I doing something wrong.

Drupal 7.61 MySQL 5.7.24 OS: Ubuntu 16.04.5 LTS

Trace: 0 /srv/www/www.example.com/public_html/includes/database/database.inc(2227): PDOStatement->execute(Array) 1/srv/www/www.example.com/public_html/includes/database/database.inc(697): DatabaseStatementBase->execute(Array, Array) 2/srv/www/www.example.com/public_html/includes/database/database.inc(1081): DatabaseConnection->query(‘ROLLBACK TO SAV…’) 3/srv/www/www.example.com/public_html/includes/database/database.inc(1989): DatabaseConnection->rollback(‘savepoint_1’) 4 /srv/www/www.example.com/public_html/modules/node/node.module(1197): DatabaseTransaction->rollback() 5/srv/www/www.example.com/public_html/sites/all/modules/entity/entity.module(290): node_save(Object(stdClass)) 6/srv/www/www.example.com/public_html/sites/all/modules/entity/includes/enti…(885): entity_save(‘node’, Object(stdClass)) 7 /srv/www/www.example.com/public_html/sites/all/modules/custom/ji_custom/Ent…(114): EntityDrupalWrapper->save() 8/srv/www/www.example.com/public_html/sites/all/modules/custom/ji_custom/Ent…(226): DonorEntity::createNewDonorFromDonationRecord(Object(EntityDrupalWrapper))