Skip to content

Commit

Permalink
feat: add rule to avoid double db call
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Sep 13, 2024
1 parent 92e1241 commit 2abeb2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rules/frappe_correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
10 changes: 10 additions & 0 deletions rules/frappe_correctness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2abeb2c

Please sign in to comment.