On Party Dashboard - Edit Subscription fails with PDO exception on first try - second try all is fine.

Comments

rlmumford’s picture

Priority: Normal » Major

This is still a bug and is on one of our clients so bumping to major.

It is trying to add the Subscriber to the party_attached_enitity twice. What I expect is happening is that the first time this modal is opened when no subscriber entity is available the following happens.

$controller->getEntityByEmail('email') Creates a new simplenews subscriber.
$controller->save() loops over all the simplenews subscribers (in this case there is only one).
$controller->save() calls entity_save on the subscriber, inserting the simplenews subscriber into the database
party_simplenews_simplenews_subscriber_insert() finds a party and attaches it
$controller->save() then tries to attach it again.

I'm not sure what the right way of avoiding this kind of scenario is.

andrewbelcher’s picture

Title: Edit Subscription fails with PDO exception on first try - second try all is fine. » PartyDefaultDataSet::save() needs to lock to prevent errors on recursion.
Project: OpenCRM Kickstart » Party
Version: » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new5.61 KB

Ok, so the issue is recursiveness in PartyDefaultDataSet::save().

The attached patch fixed that by introducing a lock on the delicate bits of the method, allowing recursive calls to happen without conflicts in data or PDO exceptions. It also means we can be better from a performance POV as we only write to the DB once. Along with that, I've update the call to setLabel() to only store if we have a lock.

This information is also passed onto the preSave() and postSave() methods so overloading classes can also implement this properly.

rlmumford’s picture

Status: Needs review » Fixed

I reviewed this fairly extensively with andrewbelcher before the patch came on here. So I'm happy to commit this now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.