Allow chaining contexts#21028
Merged
Merged
Conversation
Contributor
LOL, you should not check the 3rd checker then. |
awarecan
reviewed
Feb 13, 2019
| self.hass.bus.async_fire(EVENT_AUTOMATION_TRIGGERED, { | ||
| ATTR_NAME: self._name, | ||
| ATTR_ENTITY_ID: self.entity_id, | ||
| }, context=trigger_context) |
Contributor
There was a problem hiding this comment.
Shall use context=context here?
Member
Author
There was a problem hiding this comment.
No, we want the automation triggered to be with the new context, that way we will be able to attach automation metadata to the context.
70b936c to
7514fde
Compare
4 tasks
Merged
17 tasks
akloeckner
added a commit
to akloeckner/data.home-assistant
that referenced
this pull request
Mar 10, 2024
As resulted from a forum feedback: * [Context was indeed originally introduced to trace the cause of a change](home-assistant/core#15674) * [The user_id is used for permission checking] (https://developers.home-assistant.io/docs/auth_permissions/#the-context-object) * [Automations generate a child-context such that their actions are not run with user access](home-assistant/core#21028)
This was referenced Mar 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
When an automation is triggered, we were re-using the context from the event that triggered the automation. However, this has the unintended side effect that the automation will run with the permissions of the user triggering the automation.
It also would have caused issues in the future when doing machine learning, because although the result of an automation should be linked to the triggering event, it should not be fully attributed. It is the automation that is doing things now.
So to cover this partial relationship I'm introducing a
parent_idforContext. This will allow a context to optionally point at a previous context that caused this context to start, without conflating the concerns that the actions of the automation get attributed to the triggering event.The first thing being done with the context is firing an
automation_triggeredevent, so that it's clear that it's an automation.We need to store the context parent ID in the database. I want to do that, but I want to group a couple of more migration changes together (like increasing event type size), so have commented it out for now.
Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: