@@ -61,7 +61,7 @@ class GENERATE_TEST_RESULT_PARAM:
6161@dataclass
6262class TestResultsQuery :
6363 query : str
64- params : list [ int | str | tuple [str , ...]]
64+ params : dict [ str , int | str | tuple [str , ...]]
6565
6666
6767def convert_tuple_or_none (value : set [str ] | list [str ] | None ) -> tuple [str , ...] | None :
@@ -120,20 +120,20 @@ def generate_base_query(
120120 [f"with_cursor.{ order } { ordering_direction .name } " for order in ordering ]
121121 )
122122
123- params : list [ int | str | tuple [str , ...] | None ] = [
124- repoid ,
125- f"{ interval_num_days } days" ,
126- branch ,
127- convert_tuple_or_none (test_ids ),
128- convert_tuple_or_none (testsuites ),
129- term_filter ,
130- encode_after_or_before (after ),
131- encode_after_or_before (before ),
132- page_size ,
133- ]
134- filtered_params : list [ int | str | tuple [str , ...]] = [
135- p for p in params if p is not None
136- ]
123+ params : dict [ str , int | str | tuple [str , ...] | None ] = {
124+ "repoid" : repoid ,
125+ "interval" : f"{ interval_num_days } days" ,
126+ "branch" : branch ,
127+ "test_ids" : convert_tuple_or_none (test_ids ),
128+ "testsuites" : convert_tuple_or_none (testsuites ),
129+ "term" : term_filter ,
130+ "after" : encode_after_or_before (after ),
131+ "before" : encode_after_or_before (before ),
132+ "limit" : page_size ,
133+ }
134+ filtered_params : dict [ str , int | str | tuple [str , ...]] = {
135+ k : v for k , v in params . items () if v is not None
136+ }
137137
138138 base_query = f"""
139139with
@@ -142,12 +142,12 @@ def generate_base_query(
142142 from reports_dailytestrollups rd
143143 { "join reports_test rt on rt.id = rd.test_id" if testsuites or term else "" }
144144 where
145- rd.repoid = %s
146- and rd.date > current_date - interval %s
147- { "and rd.branch = %s" if branch else "" }
148- { "and rd.test_id in %s" if test_ids else "" }
149- { "and rt.testsuite in %s" if testsuites else "" }
150- { "and rt.name like %s" if term else "" }
145+ rd.repoid = %(repoid) s
146+ and rd.date > current_date - interval %(interval) s
147+ { "and rd.branch = %(branch) s" if branch else "" }
148+ { "and rd.test_id in %(test_ids) s" if test_ids else "" }
149+ { "and rt.testsuite in %(testsuites) s" if testsuites else "" }
150+ { "and rt.name like %(term) s" if term else "" }
151151),
152152failure_rate_cte as (
153153 select
@@ -201,10 +201,10 @@ def generate_base_query(
201201 full outer join last_duration_cte using (test_id)
202202 ) as results join reports_test rt on results.test_id = rt.id
203203) as with_cursor
204- { "where with_cursor._cursor > %s" if after else "" }
205- { "where with_cursor._cursor < %s" if before else "" }
204+ { "where with_cursor._cursor > %(before) s" if after else "" }
205+ { "where with_cursor._cursor < %(after) s" if before else "" }
206206order by { order_by }
207- limit %s
207+ limit %(limit) s
208208"""
209209 return TestResultsQuery (query = base_query , params = filtered_params )
210210
0 commit comments