Skip to content

Commit

Permalink
feat(eventuser): Migrate IssuesByTagProcessor away from EventUser
Browse files Browse the repository at this point in the history
  • Loading branch information
NisanthanNanthakumar committed Nov 9, 2023
1 parent 9bdbbaa commit 9eca754
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/sentry/data_export/processors/issues_by_tag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from sentry import tagstore
from sentry.models.eventuser import EventUser
from sentry.models.group import Group, get_group_with_redirect
from sentry.models.project import Project
from sentry.utils.eventuser import EventUser

from ..base import ExportError

Expand Down Expand Up @@ -97,7 +97,7 @@ def serialize_row(item, key):
}
if key == "user":
euser = item._eventuser
result["id"] = euser.ident if euser else ""
result["id"] = euser.user_id if euser else ""
result["email"] = euser.email if euser else ""
result["username"] = euser.username if euser else ""
result["ip_address"] = euser.ip_address if euser else ""
Expand Down
15 changes: 15 additions & 0 deletions src/sentry/utils/eventuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ def from_snuba(result: Mapping[str, Any]) -> EventUser:
user_id=result.get("user_id"),
)

@classmethod
def for_tags(cls, project_id: int, values):
"""
Finds matching EventUser objects from a list of tag values.
Return a dictionary of {tag_value: event_user}.
"""
projects = Project.objects.filter(id=project_id)
result = {}
for value in values:
keyword_filters = {value.split(":", 1)[0]: value.split(":", 1)[-1]}
eventusers = EventUser.for_projects(projects, keyword_filters)
result[value] = eventusers[0] if len(eventusers) else None
return result

@property
def tag_value(self) -> str:
"""
Expand Down
17 changes: 15 additions & 2 deletions tests/sentry/data_export/processors/test_issues_by_tag.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from datetime import timedelta

import pytest
from django.utils import timezone

from sentry.data_export.base import ExportError
from sentry.data_export.processors.issues_by_tag import IssuesByTagProcessor
from sentry.models.eventuser import EventUser
from sentry.models.group import Group
from sentry.models.project import Project
from sentry.testutils.cases import SnubaTestCase, TestCase
from sentry.testutils.helpers.datetime import before_now, iso_format
from sentry.utils.eventuser import EventUser


class IssuesByTagProcessorTest(TestCase, SnubaTestCase):
Expand All @@ -27,6 +30,8 @@ def setUp(self):
self.user = self.create_user()
self.org = self.create_organization(owner=self.user)
self.project = self.create_project(organization=self.org)
self.project.date_added = timezone.now() - timedelta(minutes=10)
self.project.save()
self.event = self.store_event(
data={
"fingerprint": ["group-1"],
Expand All @@ -36,7 +41,15 @@ def setUp(self):
project_id=self.project.id,
)
self.group = self.event.group
self.euser = EventUser.objects.get(email=self.user.email, project_id=self.project.id)
self.euser = EventUser(
project_id=self.project.id,
email=self.user.email,
username=None,
name=None,
ip_address=None,
user_id=None,
id=None,
)

def test_get_project(self):
project = IssuesByTagProcessor.get_project(project_id=self.project.id)
Expand Down

0 comments on commit 9eca754

Please sign in to comment.