diff --git a/rules/frappe_correctness.py b/rules/frappe_correctness.py index cf638bf..e531d9e 100644 --- a/rules/frappe_correctness.py +++ b/rules/frappe_correctness.py @@ -203,3 +203,10 @@ def good_cache(): from frappe.permissions import has_permission has_permission.xyz = lambda : True + +# ruleid: frappe-use-delete-doc-if-exists +if frappe.db.exists('Doc Type', {'field': "Foo"}): + frappe.db.delete('Doc Type', {'field': "Foo"}) + +# ok: frappe-use-delete-doc-if-exists +frappe.delete_doc_if_exists('Doc Type', {'field': "Foo"}) diff --git a/rules/frappe_correctness.yml b/rules/frappe_correctness.yml index fa1ad4f..23c68e3 100644 --- a/rules/frappe_correctness.yml +++ b/rules/frappe_correctness.yml @@ -348,3 +348,13 @@ rules: - "**/test_*.py" languages: [python] severity: ERROR + +- id: frappe-use-delete-doc-if-exists + pattern: | + if frappe.db.exists($DOCTYPE, $FILTERS): + frappe.db.delete($DOCTYPE, $FILTERS) + fix: | + frappe.delete_doc_if_exists($DOCTYPE, $FILTERS) + message: "Use frappe.delete_doc_if_exists() instead of checking existence and deleting separately" + languages: [python] + severity: ERROR