- 🇺🇸United States nicxvan
I am getting this issue on commerce 2.36
Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order 56 with version 6. Current version is 7. in Drupal\commerce_order\Entity\Order->preSave() (line 681 of /app/web/modules/contrib/commerce/modules/order/src/Entity/Order.php).
- Status changed to Closed: outdated
about 1 year ago 5:31pm 22 November 2023 - 🇮🇱Israel jsacksick
@nicxvan: Reopening a 2 years old issue isn't going to help.
You'd need to figure out what's causing this on your installation... This could be due to many different reasons, race conditions, badly written code... Without reproducible steps, a backtrace or anything else we can exploit, simply copy/pasting this error message isn't helping in any way.Also, in case you'd like to report a bug, open a new issue, but please make sure to provide something we can work with.
- 🇺🇸United States nicxvan
Sorry I was going to open a new issue but thought some context from this would be helpful. I was trying to reproduce it and couldn't so I didn't add additional info.
I also ended up tracking down a few separate issues. Happy to open a new issue if it comes up again. @jsacksick the exact same error is appearing for me as well.
Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order 3973 with version 7. Current version is 8. in Drupal\commerce_order\Entity\Order->preSave() (line 681 of /home/mysite/public_html/modules/contrib/commerce/modules/order/src/Entity/Order.php).There are no other backtraces in the dblog for this error and the error will appear for every order saved in the shoppping cart.
I'm not sure how to reproduce it on my own. It just appears randomly.If there's any instructions on how to cause a backtrace to appear for the next time this is triggered I would be glad to provide it for further diagnostic.
@nicxvan I am having the same issue. Please let me know if you have figured out the cause.
- 🇮🇱Israel jsacksick
If you change the setting from admin/commerce/config/orders/settings to "Prevent the save and throw an exception that may cause a fatal error..", the potential data loss will be prevented but it'll cause a crash. You should be able to see what's causing this this way.
@jsacksick
Thanks I've changed the setting as suggested.
I've also tried to access various page, forms, add and remove items from cart.
But I am not able to cause this error to trigger on it's own.Will need to observe the log and wait for the next time something to cause this error to trigger.
Thanks and happy Thanksgiving!
@jsacksick
This new error is now triggering in addition to the previous error.
Drupal\Core\Entity\EntityStorageException: Attempted to save order 3932 with version 787. Current version is 788. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of /home/mysite/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
After correcting the SqlContentEntityStorage.php and having the setting from admin/commerce/config/orders/settings to "Prevent the save and throw an exception that may cause a fatal error.." The following error is still occuring.
The difference now is that only 1 order will show these codes instead of all orders in the cart.Type commerce_order
Message Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order 4016 with version 43. Current version is 44. in Drupal\commerce_order\Entity\Order->preSave() (line 681 of public_html/modules/contrib/commerce/modules/order/src/Entity/Order.php).
Severity Error
And
Type php
Message Drupal\Core\Entity\EntityStorageException: Attempted to save order 4016 with version 43. Current version is 44. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Severity ErrorCode on line 681 of Order.php
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);if (isset($this->original) && !$this->isNew() && $this->original->getVersion() > $this->getVersion()) {
$mismatch_exception = new OrderVersionMismatchException(sprintf('Attempted to save order %s with version %s. Current version is %s.', $this->id(), $this->getVersion(), $this->original->getVersion()));
$log_only = $this->getEntityType()->get('log_version_mismatch');
if ($log_only) {
watchdog_exception('commerce_order', $mismatch_exception);
}
else {
throw $mismatch_exception;
}
}
$this->setVersion($this->getVersion() + 1);Code on line 817 of SqlContentEntityStorage.php
public function save(EntityInterface $entity) {
try {
$transaction = $this->database->startTransaction();
$return = parent::save($entity);// Ignore replica server temporarily.
\Drupal::service('database.replica_kill_switch')->trigger();
return $return;
}
catch (\Exception $e) {
if (isset($transaction)) {
$transaction->rollBack();
}
Error::logException(\Drupal::logger($this->entityTypeId), $e);
throw new EntityStorageException($e->getMessage(), $e->getCode(), $e);
}
}- 🇮🇱Israel jsacksick
@99gs3: Apply the patch from 📌 Improve the order version exception logging Fixed and switch back to logging the exception... You should now have access to the strack trace which should hopefully help.
Also, this issue is outdated / closed, so let's stop updating it please :). - 🇺🇸United States nicxvan
I've created a new issue to track this issue so we can stop updating this :D https://www.drupal.org/project/commerce/issues/3404382 🐛 OrderVersionMismatchException when updating the cart or checking out Active