Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/sentry/features/temporary.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ def register_temporary_features(manager: FeatureManager) -> None:
manager.add("organizations:statistical-detectors-rca-spans-only", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Allow organizations to configure all symbol sources.
manager.add("organizations:symbol-sources", OrganizationFeature, FeatureHandlerStrategy.INTERNAL, default=True, api_expose=True)
# Enable case-insensitive project slug lookup for qualified short ID bulk queries
manager.add("organizations:group-case-insensitive-short-id-lookup", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
# Enable tracking of tombstone hits. When enabled, the feature increments the times_seen column and updates the last_seen timestamp
manager.add("organizations:grouptombstones-hit-counter", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable static ClickHouse sampling for `OrganizationTagsEndpoint`
Expand Down
38 changes: 37 additions & 1 deletion src/sentry/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.utils.translation import gettext_lazy as _
from snuba_sdk import Column, Condition, Op

from sentry import eventstore, eventtypes, options, tagstore
from sentry import eventstore, eventtypes, features, options, tagstore
from sentry.backup.scopes import RelocationScope
from sentry.constants import DEFAULT_LOGGER_NAME, LOG_LEVELS, MAX_CULPRIT_LENGTH
from sentry.db.models import (
Expand Down Expand Up @@ -369,6 +369,42 @@ def by_qualified_short_id_bulk(
).filter(short_id_lookup, project__organization=organization_id)
)
group_lookup: set[int] = {group.short_id for group in groups}

organization = Organization.objects.get_from_cache(id=organization_id)
has_insensitive_lookup = features.has(
"organizations:group-case-insensitive-short-id-lookup", organization
)

# If any requested short_ids are missing after the exact slug match,
# fallback to a case-insensitive slug lookup to handle legacy/mixed-case slugs.
if has_insensitive_lookup:
missing_by_slug = defaultdict(list)
for sid in short_ids:
if sid.short_id not in group_lookup:
missing_by_slug[sid.project_slug].append(sid.short_id)

if len(missing_by_slug) > 0:
ci_short_id_lookup = reduce(
or_,
[
Q(project__slug__iexact=slug, short_id__in=sids)
for slug, sids in missing_by_slug.items()
],
)

fallback_groups = list(
self.exclude(
status__in=[
GroupStatus.PENDING_DELETION,
GroupStatus.DELETION_IN_PROGRESS,
GroupStatus.PENDING_MERGE,
]
).filter(ci_short_id_lookup, project__organization=organization_id)
)

groups.extend(fallback_groups)
group_lookup.update(group.short_id for group in fallback_groups)

for short_id in short_ids:
if short_id.short_id not in group_lookup:
raise Group.DoesNotExist()
Expand Down
17 changes: 17 additions & 0 deletions tests/sentry/models/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sentry.models.groupredirect import GroupRedirect
from sentry.models.grouprelease import GroupRelease
from sentry.models.groupsnooze import GroupSnooze
from sentry.models.project import Project
from sentry.models.release import Release, _get_cache_key
from sentry.replays.testutils import mock_replay
from sentry.testutils.cases import ReplaysSnubaTestCase, SnubaTestCase, TestCase
Expand Down Expand Up @@ -169,6 +170,22 @@ def test_qualified_share_id_bulk(self) -> None:
group.organization.id, [group_short_id, group_2_short_id]
)

@with_feature("organizations:group-case-insensitive-short-id-lookup")
def test_by_qualified_short_id_bulk_case_insensitive_project_slug(self) -> None:
project = self.create_project(slug="mixedcaseslug")
group = self.create_group(project=project, short_id=project.next_short_id())

Project.objects.filter(id=project.id).update(slug="MixedCaseSlug")
assert Project.objects.get(id=project.id).slug == "MixedCaseSlug"

# Re-fetch to ensure updated relation is used when computing qualified_short_id
group = Group.objects.get(id=group.id)
short_id = group.qualified_short_id

# Should resolve via case-insensitive slug fallback
resolved = Group.objects.by_qualified_short_id_bulk(group.organization.id, [short_id])
assert resolved == [group]

def test_first_last_release(self) -> None:
project = self.create_project()
release = Release.objects.create(version="a", organization_id=project.organization_id)
Expand Down
Loading