From 9355c76eca1a4a728da1665addea668b8422befd Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 31 Jul 2025 13:50:15 +0530 Subject: [PATCH] fix(email_group): prevent `StopIteration` when running import on a doctype without email fields (#33418) Signed-off-by: Akhil Narang --- frappe/email/doctype/email_group/email_group.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frappe/email/doctype/email_group/email_group.py b/frappe/email/doctype/email_group/email_group.py index d51cf6b585..0985cba6e1 100755 --- a/frappe/email/doctype/email_group/email_group.py +++ b/frappe/email/doctype/email_group/email_group.py @@ -38,10 +38,19 @@ class EmailGroup(Document): """Extract Email Addresses from given doctype and add them to the current list""" meta = frappe.get_meta(doctype) email_field = next( - d.fieldname - for d in meta.fields - if d.fieldtype in ("Data", "Small Text", "Text", "Code") and d.options == "Email" + ( + d.fieldname + for d in meta.fields + if d.fieldtype in ("Data", "Small Text", "Text", "Code") and d.options == "Email" + ), + None, ) + if not email_field: + frappe.throw( + _("No Email field found in {0}").format(doctype), + title=_("Invalid Doctype"), + ) + unsubscribed_field = "unsubscribed" if meta.get_field("unsubscribed") else None added = 0