Skip to content

Commit cad2f6d

Browse files
Abdkhan14Abdullah Khan
authored andcommitted
fix(explore): Runtime error on stringTags.hasOwnProperty (#102355)
- FIXES: [ISSUE](https://sentry.sentry.io/issues/6982212742/?alert_rule_id=14828501&alert_type=issue&notification_uuid=742f16fe-594e-465f-ba05-6850ea60d796&project=11276&referrer=slack), it's reproducible - stringTags has the correct type `TagCollection` since we always add hardcoded entries, never null/undefined - Seems like a runtime issue where the `stringTags` loses prototype, event though it's declared as a Record<...> initially - fwiw I repaced all key checks for tags on the page with `'key in obj'` --------- Co-authored-by: Abdullah Khan <[email protected]>
1 parent 841a9cc commit cad2f6d

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

static/app/components/performance/spanSearchQueryBuilder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function useEAPSpanSearchQueryBuilderProps(props: EAPSpanSearchQueryBuild
8181

8282
const numberAttributes = numberTags;
8383
const stringAttributes = useMemo(() => {
84-
if (stringTags.hasOwnProperty(SpanFields.RELEASE)) {
84+
if (SpanFields.RELEASE in stringTags) {
8585
return {
8686
...stringTags,
8787
...STATIC_SEMVER_TAGS,

static/app/views/explore/components/traceItemSearchQueryBuilder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function useFilterKeySections(
217217
...itemTypeToFilterKeySections(itemType).map(section => {
218218
return {
219219
...section,
220-
children: section.children.filter(key => stringAttributes.hasOwnProperty(key)),
220+
children: section.children.filter(key => key in stringAttributes),
221221
};
222222
}),
223223
{

static/app/views/explore/hooks/useExploreSuggestedAttribute.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ export function useExploreSuggestedAttribute({
1313
}: UseExploreSuggestedAttributeOptions) {
1414
return useCallback(
1515
(key: string): string | null => {
16-
if (stringAttributes.hasOwnProperty(key)) {
16+
if (key in stringAttributes) {
1717
return key;
1818
}
1919

20-
if (numberAttributes.hasOwnProperty(key)) {
20+
if (key in numberAttributes) {
2121
return key;
2222
}
2323

2424
const explicitStringAttribute = `tags[${key},string]`;
25-
if (stringAttributes.hasOwnProperty(explicitStringAttribute)) {
25+
if (explicitStringAttribute in stringAttributes) {
2626
return explicitStringAttribute;
2727
}
2828

2929
const explicitNumberAttribute = `tags[${key},number]`;
30-
if (numberAttributes.hasOwnProperty(explicitNumberAttribute)) {
30+
if (explicitNumberAttribute in numberAttributes) {
3131
return explicitNumberAttribute;
3232
}
3333

static/app/views/explore/hooks/useGroupByFields.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ export function useGroupByFields({
3939
.map(([_, tag]) => optionFromTag(tag, traceItemType)),
4040
...groupBys
4141
.filter(
42-
groupBy =>
43-
groupBy &&
44-
!numberTags.hasOwnProperty(groupBy) &&
45-
!stringTags.hasOwnProperty(groupBy)
42+
groupBy => groupBy && !(groupBy in numberTags) && !(groupBy in stringTags)
4643
)
4744
.map(groupBy =>
4845
optionFromTag({key: groupBy, name: groupBy, kind: FieldKind.TAG}, traceItemType)

static/app/views/explore/tables/columnEditorModal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ export function ColumnEditorModal({
5050
const tags: Array<SelectOption<string>> = useMemo(() => {
5151
let allTags = [
5252
...columns
53-
.filter(
54-
column =>
55-
!stringTags.hasOwnProperty(column) && !numberTags.hasOwnProperty(column)
56-
)
53+
.filter(column => !(column in stringTags) && !(column in numberTags))
5754
.map(column => {
5855
const kind = classifyTagKey(column);
5956
const label = prettifyTagKey(column);

static/app/views/explore/utils.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ export function findSuggestedColumns(
564564
}
565565

566566
const isStringAttribute = key.startsWith('!')
567-
? attributes.stringAttributes.hasOwnProperty(key.slice(1))
568-
: attributes.stringAttributes.hasOwnProperty(key);
567+
? key.slice(1) in attributes.stringAttributes
568+
: key in attributes.stringAttributes;
569569
const isNumberAttribute = key.startsWith('!')
570-
? attributes.numberAttributes.hasOwnProperty(key.slice(1))
571-
: attributes.numberAttributes.hasOwnProperty(key);
570+
? key.slice(1) in attributes.numberAttributes
571+
: key in attributes.numberAttributes;
572572

573573
// guard against unknown keys and aggregate keys
574574
if (!isStringAttribute && !isNumberAttribute) {
@@ -628,7 +628,7 @@ function isSimpleFilter(
628628

629629
// all number attributes are considered non trivial because they
630630
// almost always match on a range of values
631-
if (attributes.numberAttributes.hasOwnProperty(key)) {
631+
if (key in attributes.numberAttributes) {
632632
return false;
633633
}
634634

0 commit comments

Comments
 (0)