瀏覽代碼

Merge pull request #13180 from alyf-de/fix_migrate_tree

fix: Ignore "lft" and "rgt" when importing/exporting fixtures
version-14
mergify[bot] 4 年之前
committed by GitHub
父節點
當前提交
ed5ca19233
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 2 個檔案被更改,包括 15 行新增1 行删除
  1. +6
    -1
      frappe/core/doctype/data_import/data_import.py
  2. +9
    -0
      frappe/modules/import_file.py

+ 6
- 1
frappe/core/doctype/data_import/data_import.py 查看文件

@@ -211,7 +211,12 @@ def export_json(
doctype, path, filters=None, or_filters=None, name=None, order_by="creation asc" doctype, path, filters=None, or_filters=None, name=None, order_by="creation asc"
): ):
def post_process(out): def post_process(out):
del_keys = ("modified_by", "creation", "owner", "idx")
# Note on Tree DocTypes:
# The tree structure is maintained in the database via the fields "lft"
# and "rgt". They are automatically set and kept up-to-date. Importing
# them would destroy any existing tree structure. For this reason they
# are not exported as well.
del_keys = ("modified_by", "creation", "owner", "idx", "lft", "rgt")
for doc in out: for doc in out:
for key in del_keys: for key in del_keys:
if key in doc: if key in doc:


+ 9
- 0
frappe/modules/import_file.py 查看文件

@@ -107,6 +107,15 @@ def import_doc(docdict, force=False, data_import=False, pre_process=None,


doc = frappe.get_doc(docdict) doc = frappe.get_doc(docdict)


# Note on Tree DocTypes:
# The tree structure is maintained in the database via the fields "lft" and
# "rgt". They are automatically set and kept up-to-date. Importing them
# would destroy any existing tree structure.
if getattr(doc.meta, 'is_tree', None) and any([doc.lft, doc.rgt]):
print('Ignoring values of `lft` and `rgt` for {} "{}"'.format(doc.doctype, doc.name))
doc.lft = None
doc.rgt = None

doc.run_method("before_import") doc.run_method("before_import")


doc.flags.ignore_version = ignore_version doc.flags.ignore_version = ignore_version


Loading…
取消
儲存