@@ -6,7 +6,7 @@ class PilotManagerClient(FutureClient):
6
6
def get_pilot_stamps_from_refs (self , pilot_references ) -> list [str ]:
7
7
with DiracXClient () as api :
8
8
search = [{"parameter" : "PilotJobReference" , "operator" : "in" , "values" : pilot_references }]
9
- pilots = api .pilots .search (parameters = ["PilotStamp" ], search = search , sort = [])[ 0 ] # type: ignore
9
+ pilots = api .pilots .search (parameters = ["PilotStamp" ], search = search , sort = []) # type: ignore
10
10
11
11
return [pilot ["PilotStamp" ] for pilot in pilots ]
12
12
@@ -47,7 +47,10 @@ def setPilotStatus(self, pilot_reference, status, destination=None, reason=None,
47
47
def deletePilot (self , pilot_reference ):
48
48
# Translate ref to stamp (DiracX relies on stamps whereas DIRAC relies on refs)
49
49
pilot_stamps = self .get_pilot_stamps_from_refs ([pilot_reference ])
50
- pilot_stamp = pilot_stamps [0 ] # We might raise an error. This is so that we spot the error
50
+ # We don't want to raise an error.
51
+ if not pilot_stamps :
52
+ return None
53
+ pilot_stamp = pilot_stamps [0 ]
51
54
52
55
with DiracXClient () as api :
53
56
pilot_stamps = [pilot_stamp ]
@@ -155,12 +158,16 @@ def deletePilots(self, pilot_references):
155
158
search = []
156
159
if pilot_ids :
157
160
# If we have defined pilot_ids, then we have to change them to pilot_stamps
158
- search = [{"parameter" : "PilotID" , "operator" : "in" , "value " : pilot_ids }]
161
+ search = [{"parameter" : "PilotID" , "operator" : "in" , "values " : pilot_ids }]
159
162
else :
160
163
# If we have defined pilot_ids, then we have to change them to pilot_stamps
161
- search = [{"parameter" : "PilotJobReference" , "operator" : "in" , "value " : pilot_references }]
164
+ search = [{"parameter" : "PilotJobReference" , "operator" : "in" , "values " : pilot_references }]
162
165
163
166
pilots = api .pilots .search (parameters = ["PilotStamp" ], search = search , sort = []) # type: ignore
164
167
pilot_stamps = [pilot ["PilotStamp" ] for pilot in pilots ]
165
168
169
+ if not pilot_stamps :
170
+ # Avoid useless requests
171
+ return None
172
+
166
173
return api .pilots .delete_pilots (pilot_stamps = pilot_stamps ) # type: ignore
0 commit comments