@@ -85,20 +85,16 @@ async def get_desired_states(
85
85
summaries = get_subscriptions_summary (execute = False ).alias ()
86
86
87
87
to_be_changed = select (
88
- [
89
- summaries .c .subscription_id ,
90
- case (
91
- [
92
- # If the desired status is False, we want to disable it
93
- (
94
- summaries .c .desired_status == False ,
95
- SubscriptionState ("Disabled" ),
96
- ),
97
- # If the desired status is True, we want to enable it
98
- (summaries .c .desired_status == True , SubscriptionState ("Enabled" )),
99
- ]
100
- ).label ("desired_state" ),
101
- ]
88
+ summaries .c .subscription_id ,
89
+ case (
90
+ # If the desired status is False, we want to disable it
91
+ (
92
+ summaries .c .desired_status == False ,
93
+ SubscriptionState ("Disabled" ),
94
+ ),
95
+ # If the desired status is True, we want to enable it
96
+ (summaries .c .desired_status == True , SubscriptionState ("Enabled" )),
97
+ ).label ("desired_state" ),
102
98
).where (
103
99
or_ (
104
100
and_ (
@@ -151,7 +147,7 @@ async def refresh_desired_states(
151
147
152
148
if subscription_ids :
153
149
summaries = (
154
- select ([ sub_query ] )
150
+ select (sub_query )
155
151
.where (
156
152
sub_query .c .subscription_id .in_ (
157
153
[str (sub_id ) for sub_id in subscription_ids ]
@@ -165,7 +161,7 @@ async def refresh_desired_states(
165
161
# Subscriptions without an approved_to date or whose approved_to
166
162
# date is in the past, that currently have a desired_status of True
167
163
over_time = (
168
- select ([ summaries ] ).where (
164
+ select (summaries ).where (
169
165
and_ (
170
166
or_ (
171
167
summaries .c .approved_to == None ,
@@ -206,7 +202,7 @@ async def refresh_desired_states(
206
202
# Subscriptions with more usage than allocated budget
207
203
# that currently have a desired_status of True
208
204
over_budget = (
209
- select ([ summaries ] )
205
+ select (summaries )
210
206
.where (
211
207
and_ (
212
208
# To gracelessly sidestep rounding errors, allow a tolerance
@@ -222,58 +218,50 @@ async def refresh_desired_states(
222
218
223
219
over_time_or_over_budget = (
224
220
select (
225
- [
226
- literal_column ("1" ).label ("reason_enum" ),
227
- over_time .c .subscription_id ,
228
- literal_column ("uuid('" + str (admin_oid ) + "')" ).label ("admin_oid" ),
229
- literal_column ("False" ).label ("active" ),
230
- over_time .c .desired_status ,
231
- over_time .c .desired_status_info ,
232
- ]
221
+ literal_column ("1" ).label ("reason_enum" ),
222
+ over_time .c .subscription_id ,
223
+ literal_column ("uuid('" + str (admin_oid ) + "')" ).label ("admin_oid" ),
224
+ literal_column ("False" ).label ("active" ),
225
+ over_time .c .desired_status ,
226
+ over_time .c .desired_status_info ,
233
227
)
234
228
.union (
235
229
select (
236
- [
237
- literal_column ("2" ).label ("reason_enum" ),
238
- over_budget .c .subscription_id ,
239
- literal_column ("uuid('" + str (admin_oid ) + "')" ).label ("admin_oid" ),
240
- literal_column ("False" ).label ("active" ),
241
- over_budget .c .desired_status ,
242
- over_budget .c .desired_status_info ,
243
- ]
230
+ literal_column ("2" ).label ("reason_enum" ),
231
+ over_budget .c .subscription_id ,
232
+ literal_column ("uuid('" + str (admin_oid ) + "')" ).label ("admin_oid" ),
233
+ literal_column ("False" ).label ("active" ),
234
+ over_budget .c .desired_status ,
235
+ over_budget .c .desired_status_info ,
244
236
)
245
237
)
246
238
.alias ()
247
239
)
248
240
249
241
over_time_or_over_budget_reason = (
250
242
select (
251
- [
252
- over_time_or_over_budget .c .subscription_id ,
253
- over_time_or_over_budget .c .admin_oid ,
254
- over_time_or_over_budget .c .active ,
255
- case (
256
- [
257
- (
258
- func .sum (over_time_or_over_budget .c .reason_enum ) == 1 ,
259
- cast (BillingStatus .EXPIRED , Enum (BillingStatus )),
260
- ),
261
- (
262
- func .sum (over_time_or_over_budget .c .reason_enum ) == 2 ,
263
- cast (BillingStatus .OVER_BUDGET , Enum (BillingStatus )),
264
- ),
265
- (
266
- func .sum (over_time_or_over_budget .c .reason_enum ) == 3 ,
267
- cast (
268
- BillingStatus .OVER_BUDGET_AND_EXPIRED ,
269
- Enum (BillingStatus ),
270
- ),
271
- ),
272
- ],
273
- ).label ("reason" ),
274
- over_time_or_over_budget .c .desired_status_info .label ("old_reason" ),
275
- over_time_or_over_budget .c .desired_status .label ("old_desired_status" ),
276
- ]
243
+ over_time_or_over_budget .c .subscription_id ,
244
+ over_time_or_over_budget .c .admin_oid ,
245
+ over_time_or_over_budget .c .active ,
246
+ case (
247
+ (
248
+ func .sum (over_time_or_over_budget .c .reason_enum ) == 1 ,
249
+ cast (BillingStatus .EXPIRED , Enum (BillingStatus )),
250
+ ),
251
+ (
252
+ func .sum (over_time_or_over_budget .c .reason_enum ) == 2 ,
253
+ cast (BillingStatus .OVER_BUDGET , Enum (BillingStatus )),
254
+ ),
255
+ (
256
+ func .sum (over_time_or_over_budget .c .reason_enum ) == 3 ,
257
+ cast (
258
+ BillingStatus .OVER_BUDGET_AND_EXPIRED ,
259
+ Enum (BillingStatus ),
260
+ ),
261
+ ),
262
+ ).label ("reason" ),
263
+ over_time_or_over_budget .c .desired_status_info .label ("old_reason" ),
264
+ over_time_or_over_budget .c .desired_status .label ("old_desired_status" ),
277
265
)
278
266
.group_by (
279
267
over_time_or_over_budget .c .subscription_id ,
@@ -289,13 +277,11 @@ async def refresh_desired_states(
289
277
# desired status or has the wrong reason or a missing reason
290
278
over_time_or_over_budget_desired_on = (
291
279
select (
292
- [
293
- over_time_or_over_budget_reason .c .subscription_id ,
294
- over_time_or_over_budget_reason .c .admin_oid ,
295
- over_time_or_over_budget_reason .c .active ,
296
- over_time_or_over_budget_reason .c .reason ,
297
- over_time_or_over_budget_reason .c .old_reason ,
298
- ]
280
+ over_time_or_over_budget_reason .c .subscription_id ,
281
+ over_time_or_over_budget_reason .c .admin_oid ,
282
+ over_time_or_over_budget_reason .c .active ,
283
+ over_time_or_over_budget_reason .c .reason ,
284
+ over_time_or_over_budget_reason .c .old_reason ,
299
285
)
300
286
.where (
301
287
or_ (
@@ -319,12 +305,10 @@ async def refresh_desired_states(
319
305
status_table .c .reason ,
320
306
],
321
307
select (
322
- [
323
- over_time_or_over_budget_desired_on .c .subscription_id ,
324
- over_time_or_over_budget_desired_on .c .admin_oid ,
325
- over_time_or_over_budget_desired_on .c .active ,
326
- over_time_or_over_budget_desired_on .c .reason ,
327
- ]
308
+ over_time_or_over_budget_desired_on .c .subscription_id ,
309
+ over_time_or_over_budget_desired_on .c .admin_oid ,
310
+ over_time_or_over_budget_desired_on .c .active ,
311
+ over_time_or_over_budget_desired_on .c .reason ,
328
312
),
329
313
)
330
314
@@ -353,17 +337,15 @@ async def refresh_desired_states(
353
337
# but aren't currently. These are all of our subscriptions
354
338
# that are disabled but aren't over time or budget.
355
339
should_be_enabled_but_are_not = select (
356
- [
357
- summaries .c .subscription_id ,
358
- literal_column ("uuid('" + str (admin_oid ) + "')" ),
359
- literal_column ("True" ),
360
- literal_column ("NULL" ),
361
- ]
340
+ summaries .c .subscription_id ,
341
+ literal_column ("uuid('" + str (admin_oid ) + "')" ),
342
+ literal_column ("True" ),
343
+ literal_column ("NULL" ),
362
344
).where (
363
345
and_ (
364
346
not_ (
365
347
summaries .c .subscription_id .in_ (
366
- select ([ over_time_or_over_budget .c .subscription_id ] )
348
+ select (over_time_or_over_budget .c .subscription_id )
367
349
)
368
350
),
369
351
or_ (
0 commit comments