Skip to content
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

🤖 Add Feature Flag for Event Attachments in StreamGroupSerializer #82278

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion src/sentry/api/serializers/models/group_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any

from django.utils import timezone
from rest_framework.exceptions import ValidationError
from rest_framework.request import Request

from sentry import features, release_health, tsdb
Expand Down Expand Up @@ -401,7 +402,9 @@ def get_attrs(
item.project.organization,
actor=request.user,
):
return self.respond(status=404)
raise ValidationError(
"Event attachments feature is not enabled for this organization"
)

for item in item_list:
latest_event = item.get_latest_event()
Expand Down
30 changes: 30 additions & 0 deletions tests/sentry/api/serializers/test_group_stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from unittest import mock

import pytest
from rest_framework.exceptions import ValidationError

from sentry import tsdb
from sentry.api.serializers import serialize
from sentry.api.serializers.models.group_stream import (
Expand All @@ -10,6 +13,7 @@
from sentry.models.environment import Environment
from sentry.testutils.cases import BaseMetricsTestCase, PerformanceIssueTestCase, TestCase
from sentry.testutils.helpers.datetime import before_now, freeze_time
from sentry.testutils.helpers.features import Feature
from tests.sentry.issues.test_utils import SearchIssueTestMixin


Expand Down Expand Up @@ -80,3 +84,29 @@ def test_profiling_issue(self):
assert serialized["issueType"] == str(ProfileFileIOGroupType.slug)
assert [stat[1] for stat in serialized["stats"]["24h"][:-1]] == [0] * 23
assert serialized["stats"]["24h"][-1][1] == 1

def test_event_attachments_feature_flag(self):
group = self.group
request = self.make_request()
serializer = StreamGroupSerializerSnuba(
environment_ids=None, collapse=None, expand=["latestEventHasAttachments"]
)

# Test with feature flag disabled
with Feature({"organizations:event-attachments": False}):
with pytest.raises(ValidationError) as exc:
serializer.get_attrs(item_list=[group], user=request.user, request=request)
assert (
str(exc.value.detail[0])
== "Event attachments feature is not enabled for this organization"
)

# Test with feature flag enabled
with Feature({"organizations:event-attachments": True}):
attrs = serializer.get_attrs(item_list=[group], user=request.user, request=request)

# Verify the attributes were set properly
assert group in attrs
assert "latestEventHasAttachments" in attrs[group]
# Should be False by default when no attachments exist
assert attrs[group]["latestEventHasAttachments"] == False
Loading