Skip to content

Commit 9951db7

Browse files
authored
ref(grouping): Pull helper code into callers (#97514)
This PR simplifies two places in grouping code where we had a very simple helper which was only called in one place, so that now the code from the helper is just included in its caller: `get_grouping_config_dict_for_event_data` has been absorbed into `Event.get_grouping_config`, and`get_grouping_component` has been absorbed into `get_grouping_components`.
1 parent 5c7675a commit 9951db7

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/sentry/eventstore/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from sentry import eventtypes
2020
from sentry.db.models import NodeData
21+
from sentry.grouping.api import get_grouping_config_dict_for_project
2122
from sentry.grouping.variants import BaseVariant
2223
from sentry.interfaces.base import Interface, get_interfaces
2324
from sentry.issues.grouptype import GroupCategory
@@ -329,9 +330,10 @@ def get_event_metadata(self) -> dict[str, Any]:
329330

330331
def get_grouping_config(self) -> GroupingConfig:
331332
"""Returns the event grouping config."""
332-
from sentry.grouping.api import get_grouping_config_dict_for_event_data
333333

334-
return get_grouping_config_dict_for_event_data(self.data, self.project)
334+
return self.data.get("grouping_config") or get_grouping_config_dict_for_project(
335+
self.project
336+
)
335337

336338
def get_hashes_and_variants(
337339
self, config: StrategyConfiguration | None = None

src/sentry/grouping/api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from sentry import options
1111
from sentry.conf.server import DEFAULT_GROUPING_CONFIG
12-
from sentry.db.models.fields.node import NodeData
1312
from sentry.grouping.component import (
1413
AppGroupingComponent,
1514
BaseGroupingComponent,
@@ -182,11 +181,6 @@ def get_grouping_config_dict_for_project(project: Project) -> GroupingConfig:
182181
return loader.get_config_dict(project)
183182

184183

185-
def get_grouping_config_dict_for_event_data(data: NodeData, project: Project) -> GroupingConfig:
186-
"""Returns the grouping config for an event dictionary."""
187-
return data.get("grouping_config") or get_grouping_config_dict_for_project(project)
188-
189-
190184
def _get_default_base64_enhancements(config_id: str | None = None) -> str:
191185
base: str | None = DEFAULT_ENHANCEMENTS_BASE
192186
if config_id is not None and config_id in GROUPING_CONFIG_CLASSES.keys():

src/sentry/grouping/strategies/base.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,17 @@ def variant_processor(self, func: VariantProcessor) -> VariantProcessor:
262262
self.variant_processor_func = func
263263
return func
264264

265-
def get_grouping_component(
266-
self, event: Event, context: GroupingContext
267-
) -> None | BaseGroupingComponent[Any] | ReturnedVariants:
268-
"""Create a grouping component using this strategy."""
269-
interface = event.interfaces.get(self.interface_name)
270-
271-
if interface is None:
272-
return None
273-
274-
with context:
275-
return self(interface, event=event, context=context)
276-
277265
def get_grouping_components(self, event: Event, context: GroupingContext) -> ReturnedVariants:
278266
"""
279267
Return a dictionary, keyed by variant name, of components produced by this strategy.
280268
"""
281-
components_by_variant = self.get_grouping_component(event, context)
282-
if components_by_variant is None:
269+
interface = event.interfaces.get(self.interface_name)
270+
271+
if interface is None:
283272
return {}
284273

285-
assert isinstance(components_by_variant, dict)
274+
with context:
275+
components_by_variant = self(interface, event=event, context=context)
286276

287277
final_components_by_variant = {}
288278
priority_contributing_variants_by_hash = {}

0 commit comments

Comments
 (0)