Skip to content

Commit 00d9a23

Browse files
authored
fix(bug-prediction): Make tool wrapper type more precise (#103031)
rn inferred type is `Any`. makes tests a little easier to write
1 parent 5763038 commit 00d9a23

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/sentry/seer/fetch_issues/utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
MAX_NUM_DAYS_AGO_DEFAULT = 90
2222

2323

24-
def handle_fetch_issues_exceptions(func: Callable[..., Any]) -> Callable[..., Any]:
24+
class SeerResponseError(TypedDict):
25+
error: str
26+
27+
28+
def handle_fetch_issues_exceptions[R](
29+
func: Callable[..., R],
30+
) -> Callable[..., R | SeerResponseError]:
2531
@wraps(func)
26-
def wrapper(*args: Any, **kwargs: Any) -> Any:
32+
def wrapper(*args: Any, **kwargs: Any) -> R | SeerResponseError:
2733
try:
2834
return func(*args, **kwargs)
2935
except Exception as e:
3036
logger.warning("Exception in fetch_issues function", exc_info=True)
31-
return {"error": str(e)}
37+
return SeerResponseError(error=str(e))
3238

3339
return wrapper
3440

@@ -52,10 +58,6 @@ class SeerResponse(TypedDict):
5258
issues_full: list[dict[str, Any]]
5359

5460

55-
class SeerResponseError(TypedDict):
56-
error: str
57-
58-
5961
def get_repo_and_projects(
6062
organization_id: int,
6163
provider: str,

tests/sentry/seer/fetch_issues/test_by_error_type.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_simple(self) -> None:
4848
external_id="1",
4949
exception_type="KeyError",
5050
)
51+
assert "error" not in seer_response
5152
assert seer_response["issues"][0] == group.id
5253

5354
full_issues = seer_response["issues_full"][0]
@@ -159,6 +160,7 @@ def test_multiple_projects(self) -> None:
159160
external_id="1",
160161
exception_type="KeyError",
161162
)
163+
assert "error" not in seer_response
162164
assert {group_1.id, group_2.id} == set(seer_response["issues"])
163165
assert group_3.id not in seer_response["issues"]
164166
assert group_3.id not in [int(issue["id"]) for issue in seer_response["issues_full"]]
@@ -208,6 +210,7 @@ def test_last_seen_filter(self) -> None:
208210
external_id="1",
209211
exception_type="KeyError",
210212
)
213+
assert "error" not in seer_response
211214
assert seer_response["issues"] == [group.id]
212215
assert seer_response["issues_full"][0]["id"] == str(group.id)
213216
assert seer_response["issues_full"][0]["title"] == "KeyError: This a bad error"
@@ -283,6 +286,7 @@ def test_multiple_exception_types(self) -> None:
283286
external_id="1",
284287
exception_type="KeyError",
285288
)
289+
assert "error" not in seer_response
286290
assert seer_response["issues"] == [group_1.id]
287291
assert len(seer_response["issues_full"]) == 1
288292
assert seer_response["issues_full"][0]["id"] == str(group_1.id)
@@ -295,6 +299,7 @@ def test_multiple_exception_types(self) -> None:
295299
external_id="1",
296300
exception_type="ValueError",
297301
)
302+
assert "error" not in seer_response
298303
assert seer_response["issues"] == [group_2.id]
299304
assert len(seer_response["issues_full"]) == 1
300305
assert seer_response["issues_full"][0]["id"] == str(group_2.id)
@@ -409,6 +414,7 @@ def _assert_exception_type_matches(
409414
external_id="1",
410415
exception_type=search_exception_type,
411416
)
417+
assert "error" not in seer_response
412418
assert seer_response["issues"] == [expected_group.id]
413419
assert len(seer_response["issues_full"]) == 1
414420

@@ -507,6 +513,7 @@ def test_normalized_matching_multiple_groups(self) -> None:
507513
external_id="1",
508514
exception_type="valueerror",
509515
)
516+
assert "error" not in seer_response
510517
assert seer_response["issues"] == [group1.id]
511518
assert len(seer_response["issues_full"]) == 1
512519

@@ -517,6 +524,7 @@ def test_normalized_matching_multiple_groups(self) -> None:
517524
external_id="1",
518525
exception_type="type error",
519526
)
527+
assert "error" not in seer_response
520528
assert seer_response["issues"] == [group2.id]
521529
assert len(seer_response["issues_full"]) == 1
522530

tests/sentry/seer/fetch_issues/test_by_function_name.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def test_fetch_issues_end_to_end_with_metadata_and_message(self):
398398
)
399399

400400
# Basic structure checks
401+
assert "error" not in seer_response
401402
assert "issues" in seer_response
402403
assert "issues_full" in seer_response
403404
assert len(seer_response["issues"]) > 0

tests/sentry/seer/fetch_issues/test_by_text_query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_fetch_issues_message_substring_search(self):
4545
external_id=self.gh_repo.external_id,
4646
query="hello",
4747
)
48+
assert "error" not in seer_response
4849
assert len(seer_response["issues"]) > 0, "Should find issue with 'hello' substring"
4950
assert group.id in seer_response["issues"]
5051

@@ -56,6 +57,7 @@ def test_fetch_issues_message_substring_search(self):
5657
external_id=self.gh_repo.external_id,
5758
query="auth",
5859
)
60+
assert "error" not in seer_response
5961
assert len(seer_response["issues"]) > 0, "Should find issue with 'auth' substring"
6062
assert group.id in seer_response["issues"]
6163

@@ -115,6 +117,7 @@ def test_fetch_issues_culprit_search(self):
115117
query="database conn",
116118
)
117119

120+
assert "error" not in seer_response
118121
assert len(seer_response["issues"]) > 0
119122
assert group.id in seer_response["issues"]
120123

@@ -139,6 +142,7 @@ def test_fetch_issues_limit_parameter(self):
139142
limit=limit,
140143
)
141144

145+
assert "error" not in seer_response
142146
assert len(seer_response["issues"]) <= limit
143147

144148
def test_fetch_issues_from_repo_projects_returns_groups(self):

0 commit comments

Comments
 (0)