frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.12k stars 7.23k forks source link

Can't save an item (Error: Document has been modified after you have opened it) #26084

Closed FreezeS closed 3 years ago

FreezeS commented 3 years ago

Context information (for bug reports)

Output of bench version

erpnext 13.5.0
frappe 13.5.0
woocommerceconnector 1.6.0 (aadhilpm fork)

Problematic code

        for variant in variant_list:
            erp_varient_item = frappe.get_doc("Item", variant["item_name"])
            if (
                erp_varient_item.woocommerce_product_id
            ):  # varient exist in woocommerce let's update only
                r = put_request(
                    "products/{0}/variations/{1}".format(
                        erp_item.woocommerce_product_id,
                        erp_varient_item.woocommerce_product_id,
                    ),
                    variant,
                )
            else:
                woocommerce_variant = post_request(
                    "products/{0}/variations".format(erp_item.woocommerce_product_id),
                    variant,
                )

                erp_varient_item.woocommerce_product_id = woocommerce_variant.get("id")
                erp_varient_item.woocommerce_variant_id = woocommerce_variant.get("id")
                erp_varient_item.save() #<--- this is line 739

Observed result

An error is thrown when saving the item on line 739. I believe this is only a problem in v13 as people are using this branch in v12 without problems.

Expected result

The item is saved without any exceptions.

Stacktrace / full error message

Traceback (most recent call last):
  File "/home/erp/frappe-bench/apps/woocommerceconnector/woocommerceconnector/sync_products.py", line 535, in sync_erpnext_items
    sync_item_with_woocommerce(
  File "/home/erp/frappe-bench/apps/woocommerceconnector/woocommerceconnector/sync_products.py", line 739, in sync_item_with_woocommerce
    erp_varient_item.save()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 314, in _save
    self.check_if_latest()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 725, in check_if_latest
    frappe.msgprint(_("Error: Document has been modified after you have opened it") \
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint
    _raise_exception()
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.TimestampMismatchError: Error: Document has been modified after you have opened it (2021-06-15 20:22:22.159850, 2021-06-16 20:06:02.811495). Please refresh to get the latest document.

Additional information

ubuntu 20.04 with production settings

ankush commented 3 years ago

Please report it in the relevant app's repository. This doesn't have much do with ERPNext.

Re-open if you can pinpoint issue to ERPNext/Frappe code.