1212from jinja2 import Environment , PackageLoader , exceptions
1313from rctab_models .models import SubscriptionState , SubscriptionStatus
1414from sendgrid import Mail , SendGridAPIClient
15- from sqlalchemy import asc , desc , func , insert , or_ , select
15+ from sqlalchemy import and_ , asc , desc , func , insert , or_ , select
1616from sqlalchemy .sql import Select
1717
1818from rctab .constants import (
@@ -412,7 +412,12 @@ async def check_for_subs_nearing_expiry(database: Database) -> None:
412412 # We don't _have_ to filter on approved_to, but it might make things slightly quicker
413413 expiry_query = (
414414 select (summary .c .subscription_id , summary .c .approved_to , summary .c .status )
415- .where (summary .c .approved_to <= date .today () + timedelta (days = 30 ))
415+ .where (
416+ and_ (
417+ summary .c .abolished == False , # pylint: disable=singleton-comparison
418+ summary .c .approved_to <= date .today () + timedelta (days = 30 ),
419+ )
420+ )
416421 .order_by (summary .c .approved_to )
417422 )
418423 rows = await database .fetch_all (expiry_query )
@@ -436,7 +441,12 @@ async def check_for_overbudget_subs(database: Database) -> None:
436441
437442 overbudget_query = (
438443 select (summary .c .subscription_id , summary .c .allocated , summary .c .total_cost )
439- .where (summary .c .total_cost > summary .c .allocated )
444+ .where (
445+ and_ (
446+ summary .c .abolished == False , # pylint: disable=singleton-comparison
447+ summary .c .total_cost > summary .c .allocated ,
448+ )
449+ )
440450 .where (
441451 or_ (
442452 summary .c .status == SubscriptionState ("Enabled" ),
0 commit comments