core
core copied to clipboard
Remove notify support for templates
Breaking change
The notify service no longer accepts templates for title and message. This has been deprecated and planned for removal since December 2021. It affects component authors who invoke the service directly. End users who have templates in scripts and automations will not be affected as templates are still processed before the service is invoked.
Proposed change
Issue #109668 Summary: Services that define data or data_template will attempt to render a template twice if the service also defines a Schema for the attribute with a template, i.e. cv.template. This works fine if a script/automation defines a template for which is_static is true, for instance, but results in an incorrect value when the template returns something that has templating characters in it (raising an error for an invalid template or just getting an incorrect value when the template is valid). See below for an example.
Services should therefore not use cv.template. (See #122567 for more discussion.)
This fixes https://github.com/home-assistant/core/issues/109668.
Example
I discovered this when trying to use the notify service to send information about errors appearing in the main log file. Some messages I'm trying to send include errors about failures in templates, and could be truncated. So, for example:
service: notify.mobile_app_my_phone
data:
title: Error in system log
message: "The following error just occurred: {{ error }}"
When error is, for example, Template variable warning: 'name' is undefined when rendering '{% set device_id =..., message should result in:
The following error just occurred: Template variable warning: 'name' is undefined when rendering '{% set device_id =...
But the result is that a template error is generated since message is re-templated a second time (with the above, which isn't a valid template itself).
Type of change
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [x] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #109668
- This PR is related to issue: #109668
- Link to documentation pull request:
Checklist
- [x] The code change is tested and works locally.
- [x] Local tests pass. Your PR cannot be merged unless tests pass
- [x] There is no commented out code in this PR.
- [x] I have followed the development checklist
- [x] I have followed the perfect PR recommendations
- [x] The code has been formatted using Ruff (
ruff format homeassistant tests) - [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
The above do not apply to this PR.
If the code communicates with devices, web services, or third-party tools:
- [ ] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [ ] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
The above do not apply to this PR.
To help with the load of incoming pull requests:
- [x] I have reviewed two other open pull requests in this repository.
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (notify) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of notify can trigger bot actions by commenting:
@home-assistant closeCloses the pull request.@home-assistant rename Awesome new titleRenames the pull request.@home-assistant reopenReopen the pull request.@home-assistant unassign notifyRemoves the current integration label and assignees on the pull request, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:
Please rebase the branch and solve the merge conflicts.
@MartinHjelmare done.
@edenhaus are you happy?