cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't the magento orm prevent concurrent saves of the same object

Why doesn't the magento orm prevent concurrent saves of the same object

I Just recently found out that it is possible for two concurrent threads, which try to modify the same model (e.g. sales/order), to overwrite the changes made by the other process.

I've already outlined that behaviour here: http://magento.stackexchange.com/questions/58621/magento-orm-not-preventing-concurrent-db-writes.

It seems rather odd to me, that the orm (or any other layer of magento) doesn't check the db for changes before writing a model back to the db as this could potentially cause hard to track errors. Is there a reason this isn't done? (Perhaps performance)

I'm referring to the 1.* branch of magento, but I've briefly checked the source of magento 2 and think it is the same there.

 

Regards

Jens

6 REPLIES

Re: Why doesn't the magento orm prevent concurrent object saves

Nobody got any idea?

This kind of data integrity issue seems rather important to me.

 

Regards

Jens

Re: Why doesn't the magento orm prevent concurrent saves of the same object

Though it is still new and thus a culture has yet to emerge, I doubt you'll experience the same or greater technical depth here as you do at Magento SE, so the cross-post may be for naught.

 

Are you looking at what Doctrine does as a precedent? Curious for more scope.

 

 

-----
@benmarks, Developer & Community Evangelist at Magento

Re: Why doesn't the magento orm prevent concurrent saves of the same object

I hoped to catch the attention of a magento core developer by posting here.

According to the documentation doctrine provides some kind of protection against these kind of issues by providing an optimistic locking feature implemented by a version field in the database.

Re: Why doesn't the magento orm prevent concurrent saves of the same object

My guess is because locking is expensive and can confuse users. In the real world it has not proven to be a large enough issue compared to the cost. It would be fairly trivial to edit the before save function and add locks / unlocks to it and error if another thread saved. The hard part is handling what to do when it occurs.

View our great Magento Extensions

Re: Why doesn't the magento orm prevent concurrent saves of the same object

Well in my opinion ensuring that an order is always in a consistent state is a big issue. And I would have expected that magento as a professional ecommerce product made sure that two processes can't override each others changes (at least when orders are affected). Adding this feature to the orm is not that hard, but would require that all plugins and modules, saving something via the orm layer, take this new error condition into account. 

 

So, I think adding this feature now is not that easy, but would have been if it had been done during the initial development. Perhaps adding that to magento 2 might be an option.

Re: Why doesn't the magento orm prevent concurrent saves of the same object

It would be great if one of the magento development team would comment on this issue.

 

An ecommerce suite not ensuring data integrity is quite ... surprising.

 

Regards

Jens