Skip to content

feat(attachments): Include all attachment with screenshot in name #91602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/sentry/models/eventattachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ def get_crashreport_key(group_id: int) -> str:
def event_attachment_screenshot_filter(
queryset: BaseQuerySet[EventAttachment],
) -> BaseQuerySet[EventAttachment]:
# Intentionally a hardcoded list instead of a regex since current usecases do not have more 3 screenshots
return queryset.filter(
name__in=[
*[f"screenshot{f'-{i}' if i > 0 else ''}.jpg" for i in range(4)],
*[f"screenshot{f'-{i}' if i > 0 else ''}.png" for i in range(4)],
]
)
return queryset.filter(models.Q(name__icontains="screenshot"))


@dataclass(frozen=True)
Expand Down
28 changes: 18 additions & 10 deletions tests/sentry/api/endpoints/test_event_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,26 @@ def test_is_screenshot(self):
data={"fingerprint": ["group1"], "timestamp": min_ago}, project_id=self.project.id
)

attachment1 = EventAttachment.objects.create(
file = File.objects.create(name="screenshot.png", type="image/png")
EventAttachment.objects.create(
event_id=event1.event_id,
project_id=event1.project_id,
file_id=file.id,
name=file.name,
)
file = File.objects.create(name="crash_screenshot.png")
EventAttachment.objects.create(
event_id=event1.event_id,
project_id=event1.project_id,
file_id=File.objects.create(name="screenshot.png", type="image/png").id,
name="screenshot.png",
file_id=file.id,
name=file.name,
)
file = File.objects.create(name="screenshot-not.png", type="image/png")
file = File.objects.create(name="foo.png")
EventAttachment.objects.create(
event_id=event1.event_id,
project_id=event1.project_id,
file_id=file.id,
type=file.type,
name="screenshot-not.png",
name=file.name,
)

path = f"/api/0/projects/{event1.project.organization.slug}/{event1.project.slug}/events/{event1.event_id}/attachments/"
Expand All @@ -103,7 +110,8 @@ def test_is_screenshot(self):
response = self.client.get(f"{path}?query=is:screenshot")

assert response.status_code == 200, response.content
assert len(response.data) == 1
assert response.data[0]["id"] == str(attachment1.id)
assert response.data[0]["mimetype"] == "image/png"
assert response.data[0]["event_id"] == attachment1.event_id
assert len(response.data) == 2
for attachment in response.data:
assert attachment["event_id"] == event1.event_id
# foo.png will not be included
assert attachment["name"] in ["screenshot.png", "crash_screenshot.png"]
40 changes: 22 additions & 18 deletions tests/sentry/api/endpoints/test_group_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,35 @@ def test_filter(self):
assert len(response.data) == 1
assert response.data[0]["id"] == str(attachment2.id)

def test_screenshot_filter(self):
def test_screenshot_across_groups(self):
self.login_as(user=self.user)

attachment1 = self.create_attachment(type="event.attachment", file_name="screenshot.png")
self.create_attachment(type="event.attachment", file_name="screenshot-not.png")

with self.feature("organizations:event-attachments"):
response = self.client.get(self.path(screenshot=True))

assert response.status_code == 200, response.content
assert len(response.data) == 1
assert response.data[0]["id"] == str(attachment1.id)

def test_second_screenshot_filter(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this second test anymore.

self.login_as(user=self.user)

attachment1 = self.create_attachment(type="event.attachment", file_name="screenshot.png")
self.create_attachment(type="event.attachment", file_name="screenshot-not.png")
min_ago = before_now(minutes=1).isoformat()
group1_event = self.store_event(
data={"fingerprint": ["group1"], "timestamp": min_ago}, project_id=self.project.id
)
self.create_attachment(file_name="screenshot.png", event_id=group1_event.event_id)
self.create_attachment(file_name="screenshot-1.png", event_id=group1_event.event_id)
# This will not be included as name doesn't contain 'screenshot'
self.create_attachment(file_name="foo.png", event_id=group1_event.event_id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attachment will not be included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, how about a comment?

group2_event = self.store_event(
data={"fingerprint": ["group2"], "timestamp": min_ago}, project_id=self.project.id
)
self.create_attachment(file_name="crash_screenshot.png", event_id=group2_event.event_id)

with self.feature("organizations:event-attachments"):
response = self.client.get(self.path(screenshot=True))

assert response.status_code == 200, response.content
assert len(response.data) == 1
assert response.data[0]["id"] == str(attachment1.id)
assert len(response.data) == 3
for attachment in response.data:
# foo.png will not be included
assert attachment["name"] in [
"screenshot.png",
"screenshot-1.png",
"crash_screenshot.png",
]
assert attachment["event_id"] in [group1_event.event_id, group2_event.event_id]

def test_without_feature(self):
self.login_as(user=self.user)
Expand Down
Loading