U4-1564 - Saving an item in an AfterSave event can create an infinite loop

Created by Sebastiaan Janssen 28 Jan 2013, 14:14:16 Updated by Mihai Savu 11 Nov 2014, 00:49:51

Relates to: U4-1372

One of the side effects of saving properties properly is that you can now easily create in infinite loop: Suppose you're doing something in the AfterSave event and then call Save() again. You'll immediately end up in the AfterSave event again, which is going to kick off another Save() and so on and so on.

In v6 (unlike in v4) you can actually change property values properly in the BeforeSave event and that should be more than enough for most people. If you really must use the AfterSave to resave the item, then it is up to you to make sure there's some checking being done so you will not end up in an infinite loop. So be aware of this.

Comments

Sebastiaan Janssen 28 Jan 2013, 14:23:04

We're going to implement an optional parameter in the Save method which allows you to turn of subsequent events. So Save(false) will not fire any more events.


Mihai Savu 11 Nov 2014, 00:49:51

In v4.7.2 you can also change property values properly in the Document_BeforeSave event. Just load the new values like this Document newValues = new Document(sender.Id); and set the property value of newValues Document. Don't call Save() because this is a BeforeSave event, the actual Save is about to happen.


Priority: Normal

Type: Task

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: False

Fix Submitted:

Affected versions: 6.0.0

Due in version:

Sprint:

Story Points:

Cycle: