From c174881534f89f2a8231de2c6b9c65f869bb820c Mon Sep 17 00:00:00 2001 From: Shrihari Mahabal Date: Tue, 10 Mar 2026 13:26:38 +0530 Subject: [PATCH] refactor: change existing functionality in framework to check if get_docs is working --- frappe/core/doctype/user/user.py | 10 ++++------ frappe/core/doctype/user_invitation/user_invitation.py | 3 +-- frappe/desk/doctype/event/event.py | 6 ++---- .../doctype/auto_email_report/auto_email_report.py | 4 ++-- frappe/utils/scheduler.py | 3 +-- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index b1831d59f9..81e1688bad 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -617,18 +617,16 @@ class User(Document): frappe.db.delete("List Filter", {"for_user": self.name}) # Remove user from Note's Seen By table - seen_notes = frappe.get_all("Note", filters=[["Note Seen By", "user", "=", self.name]], pluck="name") - for note_id in seen_notes: - note = frappe.get_doc("Note", note_id) + seen_notes = frappe.get_docs("Note", filters=[["Note Seen By", "user", "=", self.name]]) + for note in seen_notes: for row in note.seen_by: if row.user == self.name: note.remove(row) note.save(ignore_permissions=True) # Unlink user from all of its invitation docs - invites = frappe.db.get_all("User Invitation", filters={"email": self.name}, pluck="name") - for invite in invites: - invite_doc = frappe.get_doc("User Invitation", invite) + invites = frappe.get_docs("User Invitation", filters={"email": self.name}) + for invite_doc in invites: invite_doc.user = None invite_doc.save(ignore_permissions=True) diff --git a/frappe/core/doctype/user_invitation/user_invitation.py b/frappe/core/doctype/user_invitation/user_invitation.py index 4d098d5af7..582ee2dfbe 100644 --- a/frappe/core/doctype/user_invitation/user_invitation.py +++ b/frappe/core/doctype/user_invitation/user_invitation.py @@ -206,12 +206,11 @@ class UserInvitation(Document): def mark_expired_invitations() -> None: days = 3 - invitations_to_expire = frappe.db.get_all( + invitations_to_expire = frappe.get_docs( "User Invitation", filters={"status": "Pending", "creation": ["<", frappe.utils.add_days(frappe.utils.now(), -days)]}, ) for invitation in invitations_to_expire: - invitation = frappe.get_doc("User Invitation", invitation.name) invitation.expire() # to avoid losing work in case the job times out without finishing frappe.db.commit() # nosemgrep diff --git a/frappe/desk/doctype/event/event.py b/frappe/desk/doctype/event/event.py index 99af59a417..33e480bb8c 100644 --- a/frappe/desk/doctype/event/event.py +++ b/frappe/desk/doctype/event/event.py @@ -137,7 +137,7 @@ class Event(Document): return for participant in self.event_participants: - if communications := frappe.get_all( + if communications := frappe.get_docs( "Communication", filters=[ ["Communication", "reference_doctype", "=", self.doctype], @@ -145,11 +145,9 @@ class Event(Document): ["Communication Link", "link_doctype", "=", participant.reference_doctype], ["Communication Link", "link_name", "=", participant.reference_docname], ], - pluck="name", distinct=True, ): - for comm in communications: - communication = frappe.get_doc("Communication", comm) + for communication in communications: self.update_communication(participant, communication) else: meta = frappe.get_meta(participant.reference_doctype) diff --git a/frappe/email/doctype/auto_email_report/auto_email_report.py b/frappe/email/doctype/auto_email_report/auto_email_report.py index f3109511a2..96f3ae0c44 100644 --- a/frappe/email/doctype/auto_email_report/auto_email_report.py +++ b/frappe/email/doctype/auto_email_report/auto_email_report.py @@ -359,8 +359,8 @@ def process_auto_email_report(report): def send_monthly(): """Check reports to be sent monthly""" - for report in frappe.get_all("Auto Email Report", {"enabled": 1, "frequency": "Monthly"}): - frappe.get_doc("Auto Email Report", report.name).send() + for report in frappe.get_docs("Auto Email Report", filters={"enabled": 1, "frequency": "Monthly"}): + report.send() def make_links(columns, data): diff --git a/frappe/utils/scheduler.py b/frappe/utils/scheduler.py index 2d8075f8e9..8555bdd639 100644 --- a/frappe/utils/scheduler.py +++ b/frappe/utils/scheduler.py @@ -132,10 +132,9 @@ def enqueue_events_for_site(site: str) -> None: def enqueue_events() -> list[str] | None: if schedule_jobs_based_on_activity(): enqueued_jobs = [] - all_jobs = frappe.get_all("Scheduled Job Type", filters={"stopped": 0}, fields="*") + all_jobs = frappe.get_docs("Scheduled Job Type", filters={"stopped": 0}) random.shuffle(all_jobs) for job_type in all_jobs: - job_type = frappe.get_doc(doctype="Scheduled Job Type", **job_type) try: if job_type.enqueue(): enqueued_jobs.append(job_type.method)