-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix @trace
not wrapping some state methods that return coroutines correctly
#15647
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Instrument `state` and `state_group` storage-related operations to better picture what's happening when tracing. | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,7 +16,6 @@ | |||||||||||||||||||||||||
TYPE_CHECKING, | ||||||||||||||||||||||||||
AbstractSet, | ||||||||||||||||||||||||||
Any, | ||||||||||||||||||||||||||
Awaitable, | ||||||||||||||||||||||||||
Callable, | ||||||||||||||||||||||||||
Collection, | ||||||||||||||||||||||||||
Dict, | ||||||||||||||||||||||||||
|
@@ -175,9 +174,9 @@ async def get_state_groups( | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@trace | ||||||||||||||||||||||||||
@tag_args | ||||||||||||||||||||||||||
def _get_state_groups_from_groups( | ||||||||||||||||||||||||||
async def _get_state_groups_from_groups( | ||||||||||||||||||||||||||
self, groups: List[int], state_filter: StateFilter | ||||||||||||||||||||||||||
) -> Awaitable[Dict[int, StateMap[str]]]: | ||||||||||||||||||||||||||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
175
to
-180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we somehow type this to catch it in CI before we see it in the logs?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if inspect.iscoroutine(result):
def await_coroutine():
try:
await result
finally:
scope.__exit__(None, None, None)
# the original method returned a coroutine,
# so we create another coroutine wrapping it, that calls __exit__.
return await_coroutine() (wholly untested) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @squahtx Good shout! It looks plausible and I can introduce it in another PR ⏩ I know this PR wouldn't be necessary if that worked but this is the quick and easy fix and it aligns with the rest of what we're doing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tackling this in #15650 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'm in favour of landing this PR. |
||||||||||||||||||||||||||
) -> Dict[int, StateMap[str]]: | ||||||||||||||||||||||||||
"""Returns the state groups for a given set of groups, filtering on | ||||||||||||||||||||||||||
types of state events. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -190,7 +189,9 @@ def _get_state_groups_from_groups( | |||||||||||||||||||||||||
Dict of state group to state map. | ||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return self.stores.state._get_state_groups_from_groups(groups, state_filter) | ||||||||||||||||||||||||||
return await self.stores.state._get_state_groups_from_groups( | ||||||||||||||||||||||||||
groups, state_filter | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@trace | ||||||||||||||||||||||||||
@tag_args | ||||||||||||||||||||||||||
|
@@ -349,9 +350,9 @@ async def get_state_ids_for_event( | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@trace | ||||||||||||||||||||||||||
@tag_args | ||||||||||||||||||||||||||
def get_state_for_groups( | ||||||||||||||||||||||||||
async def get_state_for_groups( | ||||||||||||||||||||||||||
self, groups: Iterable[int], state_filter: Optional[StateFilter] = None | ||||||||||||||||||||||||||
) -> Awaitable[Dict[int, MutableStateMap[str]]]: | ||||||||||||||||||||||||||
) -> Dict[int, MutableStateMap[str]]: | ||||||||||||||||||||||||||
"""Gets the state at each of a list of state groups, optionally | ||||||||||||||||||||||||||
filtering by type/state_key | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -363,7 +364,7 @@ def get_state_for_groups( | |||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||
Dict of state group to state map. | ||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
return self.stores.state._get_state_for_groups( | ||||||||||||||||||||||||||
return await self.stores.state._get_state_for_groups( | ||||||||||||||||||||||||||
groups, state_filter or StateFilter.all() | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using same changelog as #15610 so the changelog entry merges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this only works if you use the same suffix as the other entry, i.e.
.misc
here. Easy enough to merge at release time though.