Notification not send on new document

I have created a custom doctype and a webform to let anyone create an entry. —> works

I have created a notification to get notified when a document get created - Send Alert on new)
Configured with Role ‘Website Manager’ as recipient (Doctype permission is set for the Website Manager)
—> The notification fails with

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/email/doctype/notification/notification.py", line 131, in send
    self.send_an_email(doc, context)
      self = <Notification: New Registered Device>
      doc = <Document: REG-DEVICE-0097>
      context = {'doc': <Document: REG-DEVICE-0097>, 'alert': <Notification: New Registered Device>, 'comments': None}
  File "apps/frappe/frappe/email/doctype/notification/notification.py", line 207, in send_an_email
    recipients, cc, bcc = self.get_list_of_recipients(doc, context)
      self = <Notification: New Registered Device>
      doc = <Document: REG-DEVICE-0097>
      context = {'doc': <Document: REG-DEVICE-0097>, 'alert': <Notification: New Registered Device>, 'comments': None}
      formataddr = <function formataddr at 0x7fa9671697e0>
      make_communication = <function _make at 0x7fa953f2ba30>
      subject = ' REG-DEVICE-0097 created by A User  '
      attachments = None
  File "apps/frappe/frappe/email/doctype/notification/notification.py", line 300, in get_list_of_recipients
    emails = get_info_based_on_role(recipient.receiver_by_role, "email")
      self = <Notification: New Registered Device>
      doc = <Document: REG-DEVICE-0097>
      context = {'doc': <Document: REG-DEVICE-0097>, 'alert': <Notification: New Registered Device>, 'comments': None}
      recipients = []
      cc = ['name@mymail.com']
      bcc = []
      recipient = <NotificationRecipient: ecac7ac57c parent=New Registered Device>
  File "apps/frappe/frappe/core/doctype/role/role.py", line 69, in get_info_based_on_role
    users = frappe.get_list(
      role = 'Website Manager'
      field = 'email'
  File "apps/frappe/frappe/__init__.py", line 1879, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
      doctype = 'Has Role'
      args = ()
      kwargs = {'filters': {'role': 'Website Manager', 'parenttype': 'User'}, 'parent_doctype': 'User', 'fields': ['parent as user_name']}
      frappe = <module 'frappe' from 'apps/frappe/frappe/init.py'>
  File "apps/frappe/frappe/model/db_query.py", line 112, in execute
    raise frappe.PermissionError(self.doctype)
      self = <frappe.model.db_query.DatabaseQuery object at 0x7fa953c72530>
      fields = ['parent as user_name']
      filters = {'role': 'Website Manager', 'parenttype': 'User'}
      or_filters = None
      docstatus = None
      group_by = None
      order_by = 'KEEP_DEFAULT_ORDERING'
      limit_start = False
      limit_page_length = None
      as_list = False
      with_childnames = False
      debug = False
      ignore_permissions = False
      user = None
      with_comment_count = False
      join = 'left join'
      distinct = False
      start = None
      page_length = None
      limit = None
      ignore_ifnull = False
      save_user_settings = False
      save_user_settings_fields = False
      update = None
      add_total_row = None
      user_settings = None
      reference_doctype = None
      run = True
      strict = True
      ignore_ddl = False
      parent_doctype = 'User'
      pluck = None
frappe.exceptions.PermissionError: Has Role

What’s wrong?

Your are sending email notification
Did you configured Email account?

Yes, all is configured.

Ex. if I configure the notification to send on ‘Value Change’ of a field (on an existing doc) all works perfectly fine and i get the notification…

The problem seems to be that anyone can create the doctype, but anyone cannot know all users’ roles. The code checks if the current user has permissions to see other users roles.

This is probably a bug (not intended), and it needs careful fixing so we don’t create a security issue.

2 Likes

Thank you for the reply.
If it is like that, seems nothing i can do (as I’m not a developer at that level to fix it)

Might someone has an idea or workaround. All i want is to get informed if someone submit a webform to be able to react.

Might someone has an idea or workaround. All i want is to get informed if someone submit a webform to be able to react.

An easy workaround would be to use explicit email ids as recipients, not based on role.

1 Like

Seems this is not doable as it either asks for setting a role or a field in the doc with an email address (which i do not have)
Setting only an email in CC in the notification definition does not let me save the document.

Might i miss something, how to make it happen :frowning:

[Update] Setting the field to ‘owner’ and providing a mailaddress in CC field at least works as a work around.

I have the same problem. It work with roles before (for us it stopped working in Nov '22), even when a Guest was creating the new doc.

There should be a way to send notifications (role-based) when a guest is submitting a new web form (and thus creating a new doc).

GitHub issue

2 Likes

Thanks a lot, this has helped me!

Can anyone please share how to set email accounts to enable email notifications.?

Am facing issue that email notifications are not working now