66from collections import defaultdict
77from collections .abc import Callable , Mapping
88from datetime import datetime , timedelta
9- from typing import Any , Literal , NotRequired
9+ from typing import Any , Literal , NotRequired , TypedDict
1010
1111from django import forms
1212from django .core .cache import cache
@@ -120,6 +120,13 @@ def clean(self) -> dict[str, Any] | None:
120120 return cleaned_data
121121
122122
123+ class _QSTypedDict (TypedDict ):
124+ id : int
125+ type : int
126+ project_id : int
127+ project__organization_id : int
128+
129+
123130class BaseEventFrequencyCondition (EventCondition , abc .ABC ):
124131 intervals = STANDARD_INTERVALS
125132 form_cls = EventFrequencyForm
@@ -377,7 +384,8 @@ def get_chunked_result(
377384 return batch_totals
378385
379386 def get_error_and_generic_group_ids (
380- self , groups : list [QuerySet ]
387+ self ,
388+ groups : QuerySet [Group , _QSTypedDict ],
381389 ) -> tuple [list [int ], list [int ]]:
382390 """
383391 Separate group ids into error group ids and generic group ids
@@ -386,14 +394,18 @@ def get_error_and_generic_group_ids(
386394 error_issue_ids = []
387395
388396 for group in groups :
389- issue_type = get_group_type_by_type_id (group . get ( "type" ) )
397+ issue_type = get_group_type_by_type_id (group [ "type" ] )
390398 if GroupCategory (issue_type .category ) == GroupCategory .ERROR :
391- error_issue_ids .append (group . get ( "id" ) )
399+ error_issue_ids .append (group [ "id" ] )
392400 else :
393- generic_issue_ids .append (group . get ( "id" ) )
401+ generic_issue_ids .append (group [ "id" ] )
394402 return (error_issue_ids , generic_issue_ids )
395403
396- def get_value_from_groups (self , groups : list [QuerySet ] | None , value : str ) -> int | None :
404+ def get_value_from_groups (
405+ self ,
406+ groups : QuerySet [Group , _QSTypedDict ] | None ,
407+ value : Literal ["id" , "project_id" , "project__organization_id" ],
408+ ) -> int | None :
397409 result = None
398410 if groups :
399411 group = groups [0 ]
@@ -426,7 +438,7 @@ def batch_query_hook(
426438 ) -> dict [int , int ]:
427439 batch_sums : dict [int , int ] = defaultdict (int )
428440 groups = Group .objects .filter (id__in = group_ids ).values (
429- "id" , "type" , "project__organization_id"
441+ "id" , "type" , "project_id" , " project__organization_id"
430442 )
431443 error_issue_ids , generic_issue_ids = self .get_error_and_generic_group_ids (groups )
432444 organization_id = self .get_value_from_groups (groups , "project__organization_id" )
@@ -489,7 +501,7 @@ def batch_query_hook(
489501 ) -> dict [int , int ]:
490502 batch_totals : dict [int , int ] = defaultdict (int )
491503 groups = Group .objects .filter (id__in = group_ids ).values (
492- "id" , "type" , "project__organization_id"
504+ "id" , "type" , "project_id" , " project__organization_id"
493505 )
494506 error_issue_ids , generic_issue_ids = self .get_error_and_generic_group_ids (groups )
495507 organization_id = self .get_value_from_groups (groups , "project__organization_id" )
@@ -664,21 +676,21 @@ def batch_query_hook(
664676 project_id = self .get_value_from_groups (groups , "project_id" )
665677
666678 if not project_id :
667- return {group . get ( "id" ) : 0 for group in groups }
679+ return {group [ "id" ] : 0 for group in groups }
668680
669681 session_count_last_hour = self .get_session_count (project_id , environment_id , start , end )
670682 avg_sessions_in_interval = self .get_session_interval (
671683 session_count_last_hour , self .get_option ("interval" )
672684 )
673685
674686 if not avg_sessions_in_interval :
675- return {group . get ( "id" ) : 0 for group in groups }
687+ return {group [ "id" ] : 0 for group in groups }
676688
677689 error_issue_ids , generic_issue_ids = self .get_error_and_generic_group_ids (groups )
678690 organization_id = self .get_value_from_groups (groups , "project__organization_id" )
679691
680692 if not (error_issue_ids and organization_id ):
681- return {group . get ( "id" ) : 0 for group in groups }
693+ return {group [ "id" ] : 0 for group in groups }
682694
683695 error_issue_count = self .get_chunked_result (
684696 tsdb_function = self .tsdb .get_sums ,
0 commit comments