Skip to content
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
25 changes: 25 additions & 0 deletions static/app/views/explore/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ describe('viewSamplesTarget', () => {
},
});
});

it('drill down with no value group by uses !has filter', () => {
const location = LocationFixture();
const target = viewSamplesTarget({
location,
query: '',
fields: ['foo'],
groupBys: ['user.id'],
visualizes: [visualize],
sorts: [sort],
row: {
'user.id': undefined,
'count(span.duration)': 10,
},
projects,
});
expect(target).toMatchObject({
query: {
field: ['foo', 'span.duration'],
mode: 'samples',
query: '!has:user.id',
sort: ['-span.duration'],
},
});
});
});

describe('findSuggestedColumns', () => {
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/explore/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ export function generateTargetQuery({
} else {
search.setFilterValues(groupBy, [value]);
}
} else if (!defined(value)) {
search.addFilterValue('!has', groupBy);
}
}
Comment on lines +324 to 326
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The generateTargetQuery function silently ignores numeric groupBy values when drilling down into samples, causing the drilldown to show unfiltered results instead of the expected filtered data.
Severity: MEDIUM

Suggested Fix

Add a generic handler to the generateTargetQuery function to process numeric values. This can be done by adding an else if (typeof value === 'number') block that appends the filter condition newQuery.push(${groupBy}:${value}); to the query, similar to how string values are handled.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/app/views/explore/utils.tsx#L324-L326

Potential issue: The `generateTargetQuery` function in
`static/app/views/explore/utils.tsx` lacks a handler for numeric values in `groupBy`
columns. While there are specific handlers for fields like `project.id` and a generic
handler for strings, any other numeric value (e.g., `http.status_code` or custom numeric
attributes) will fall through all conditions. Consequently, when a user groups by a
numeric attribute and clicks "View Samples", the numeric filter is silently skipped.
This leads to the samples page showing all spans instead of the correctly filtered
subset, which is incorrect and misleading behavior.

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


Expand Down
Loading