Get_url does not work for scheduled notifications

I have a few active Notifications that send emails related to a specific DocType and also include a link to the document in the email as nicely described here with:

<a href="{{ frappe.utils.get_url_to_form(doc.doctype, }}">{{ doc.title}}</a>

The correct URL is returned and included in the email for the notifications of Send Alert On of “Value Change”, i.e.

However, the wrong URL is returned for notifications of Send Alert On of “Days After” and “Days Before”, it returns http://site1.local/app/mydoctype/mydocname

Some digging makes me think that get_url() and get_url_to_form() does not work for scheduled emails. This post mentions that get_site_name() will not work for scheduled events.

For now, I solved it by hard coding my public site name into the Notification which isn’t ideal, i.e.

<a href=" {{ '' ~ }} ">{{ doc.title}}</a>

Any better alternatives are welcome. Thanks so much!

I’m currently using
ERPNext: v13.38.0 (version-13)
Frappe Framework: v13.41.0 (version-13)

You need to set host_name in your site config if the function is to be called from non-request context. In background jobs there’s no easy way to guess your public facing URL.


  "host_name":  ""
1 Like