Skip to content

Conversation

@scttcper
Copy link
Member

Add support for including empty tag values in the group tagkey values endpoints when the organizations:issue-tags-include-empty-values feature flag is enabled.

Currently will display an empty string and the count and will need to follow up with frontend fixes.

image

part of https://linear.app/getsentry/issue/RTC-1181/

Add support for including empty tag values in the group tagkey values
endpoints when the organizations:issue-tags-include-empty-values feature
flag is enabled.

Endpoints affected:
- api/0/issues/{id}/tags/{key}/values/
- api/0/issues/{id}/tags/{key}/

Changes:
- Add include_empty_values parameter to get_group_tag_key, get_group_tag_value_iter,
  get_group_tag_value_paginator, get_group_tag_value_count, and get_top_group_tag_values methods
- Update __get_tag_key_and_top_values to conditionally exclude empty values
- Update group_tagkey_values and group_tagkey_details endpoints to check feature flag
- Add feature flag organizations:issue-tags-include-empty-values
- Add tests for empty tag inclusion behavior
@linear
Copy link

linear bot commented Oct 23, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 23, 2025
@scttcper scttcper marked this pull request as ready for review October 23, 2025 22:06
@scttcper scttcper requested review from a team as code owners October 23, 2025 22:06
@scttcper scttcper requested a review from wedamija October 23, 2025 22:06
self.key_column: [key],
}
if not include_empty_values:
filters[self.key_column] = [key]
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Tag Key Filter Ignored When Including Empty Values

When include_empty_values is True in get_group_tag_value_iter, the query incorrectly omits the filter for the specific tag key. This results in the method returning values for all tag keys in the group, instead of only the requested one. The include_empty_values parameter was intended to control filtering of empty values, not the tag key itself.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

Bot comment seems reasonable — can you explain why you're now omitting the key filter?

Copy link
Member Author

Choose a reason for hiding this comment

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

added a comment

Comment on lines 1408 to 1410
if not include_empty_values:
filters[self.key_column] = [key]
dataset, filters = self.apply_group_filters(group, filters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: When include_empty_values is true in get_group_tag_value_iter, the filter for the specific tag key is omitted, causing the query to return values for all tags.
Severity: CRITICAL | Confidence: 0.95

🔍 Detailed Analysis

In the `get_group_tag_value_iter` method, when `include_empty_values` is `True`, a filter to restrict the query to the specified tag `key` is not applied. The line `filters[self.key_column] = [key]` is only executed when `include_empty_values` is `False`. Without this filter, the Snuba query will fetch values from all tag keys for the given group, not just the one requested. This leads to incorrect data being returned to the client, including wrong tag values, inaccurate counts, and faulty pagination, as the aggregations and limits are applied to a much larger, incorrect dataset.

💡 Suggested Fix

The filter filters[self.key_column] = [key] should be applied regardless of the value of include_empty_values. Move this line of code so that it is executed before the if not include_empty_values: block, ensuring the query is always correctly filtered by the requested tag key.

🤖 Prompt for AI Agent
Fix this bug. In src/sentry/tagstore/snuba/backend.py at lines 1408-1410: In the
`get_group_tag_value_iter` method, when `include_empty_values` is `True`, a filter to
restrict the query to the specified tag `key` is not applied. The line
`filters[self.key_column] = [key]` is only executed when `include_empty_values` is
`False`. Without this filter, the Snuba query will fetch values from all tag keys for
the given group, not just the one requested. This leads to incorrect data being returned
to the client, including wrong tag values, inaccurate counts, and faulty pagination, as
the aggregations and limits are applied to a much larger, incorrect dataset.

Did we get this right? 👍 / 👎 to inform future reviews.

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/tagstore/snuba/backend.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #102048      +/-   ##
===========================================
+ Coverage   75.54%    80.90%   +5.36%     
===========================================
  Files        8819      8822       +3     
  Lines      389819    389901      +82     
  Branches    24799     24799              
===========================================
+ Hits       294475    315445   +20970     
+ Misses      94982     74094   -20888     
  Partials      362       362              

# Whether to allow issue only search on the issue list
manager.add("organizations:issue-search-allow-postgres-only-search", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
# Include empty tag count in issue tag totals/values
manager.add("organizations:issue-tags-include-empty-values", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in temporary.py — just confirming that we plan to roll this out to all orgs eventually?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! asap. Felt dangerous enough to put behind a flag and it needs frontend changes

self.key_column: [key],
}
if not include_empty_values:
filters[self.key_column] = [key]
Copy link
Contributor

Choose a reason for hiding this comment

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

Bot comment seems reasonable — can you explain why you're now omitting the key filter?

Copy link
Contributor

@thetruecpaul thetruecpaul left a comment

Choose a reason for hiding this comment

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

LGTM

@scttcper scttcper merged commit 73bc978 into master Oct 30, 2025
68 checks passed
@scttcper scttcper deleted the scttcper/issue-tagkey-values-include-empty-values branch October 30, 2025 18:32
shashjar pushed a commit that referenced this pull request Nov 4, 2025
…02048)

Add support for including empty tag values in the group tagkey values
endpoints when the organizations:issue-tags-include-empty-values feature
flag is enabled.

Currently will display an empty string and the count and will need to
follow up with frontend fixes.

<img width="924" height="341" alt="image"
src="https://github.com/user-attachments/assets/abe4744e-ebbd-4340-bdaa-fe78f9af9957"
/>

part of https://linear.app/getsentry/issue/RTC-1181/
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
…02048)

Add support for including empty tag values in the group tagkey values
endpoints when the organizations:issue-tags-include-empty-values feature
flag is enabled.

Currently will display an empty string and the count and will need to
follow up with frontend fixes.

<img width="924" height="341" alt="image"
src="https://github.com/user-attachments/assets/abe4744e-ebbd-4340-bdaa-fe78f9af9957"
/>

part of https://linear.app/getsentry/issue/RTC-1181/
@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants