Browse Source

fix: Obey force kwarg frappe.reload_doc

version-14
Gavin D'souza 3 years ago
parent
commit
3cd047becf
1 changed files with 6 additions and 14 deletions
  1. +6
    -14
      frappe/modules/import_file.py

+ 6
- 14
frappe/modules/import_file.py View File

@@ -107,7 +107,6 @@ def import_file_by_path(
Returns: Returns:
[bool]: True if import takes place. False if it wasn't imported. [bool]: True if import takes place. False if it wasn't imported.
""" """
frappe.flags.dt = frappe.flags.dt or []
try: try:
docs = read_doc_from_file(path) docs = read_doc_from_file(path)
except IOError: except IOError:
@@ -121,20 +120,19 @@ def import_file_by_path(
docs = [docs] docs = [docs]


for doc in docs: for doc in docs:

# modified timestamp in db, none if doctype's first import # modified timestamp in db, none if doctype's first import
db_modified_timestamp = frappe.db.get_value(doc["doctype"], doc["name"], "modified") db_modified_timestamp = frappe.db.get_value(doc["doctype"], doc["name"], "modified")
is_db_timestamp_latest = db_modified_timestamp and ( is_db_timestamp_latest = db_modified_timestamp and (
get_datetime(doc.get("modified")) <= get_datetime(db_modified_timestamp) get_datetime(doc.get("modified")) <= get_datetime(db_modified_timestamp)
) )


if not force or db_modified_timestamp:
try:
stored_hash = None
if doc["doctype"] == "DocType":
if not force and db_modified_timestamp:
stored_hash = None
if doc["doctype"] == "DocType":
try:
stored_hash = frappe.db.get_value(doc["doctype"], doc["name"], "migration_hash") stored_hash = frappe.db.get_value(doc["doctype"], doc["name"], "migration_hash")
except Exception:
frappe.flags.dt += [doc["doctype"]]
except Exception:
pass


# if hash exists and is equal no need to update # if hash exists and is equal no need to update
if stored_hash and stored_hash == calculated_hash: if stored_hash and stored_hash == calculated_hash:
@@ -172,12 +170,6 @@ def import_file_by_path(
return True return True




def is_timestamp_changed(doc):
# check if timestamps match
db_modified = frappe.db.get_value(doc["doctype"], doc["name"], "modified")
return not (db_modified and get_datetime(doc.get("modified")) == get_datetime(db_modified))


def read_doc_from_file(path): def read_doc_from_file(path):
doc = None doc = None
if os.path.exists(path): if os.path.exists(path):


Loading…
Cancel
Save