Skip to content

Commit c95793c

Browse files
committed
lint fixes
1 parent a498e48 commit c95793c

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

functions-python/helpers/feed_status.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from sqlalchemy import text
44
from shared.database_gen.sqlacodegen_models import Gtfsdataset, Feed, t_feedsearch
55
from shared.database.database import refresh_materialized_view
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from sqlalchemy.orm import Session
10+
611

712
# query to update the status of the feeds based on the service date range of the latest dataset
813
def update_feed_statuses_query(session: "Session", stable_feed_ids: list[str]):
@@ -41,24 +46,25 @@ def update_feed_statuses_query(session: "Session", stable_feed_ids: list[str]):
4146
try:
4247
diff_counts: dict[str, int] = {}
4348

44-
filters = [
45-
Feed.id == latest_dataset_subq.c.feed_id,
46-
Feed.status != text("'deprecated'::status"),
47-
Feed.status != text("'development'::status"),
48-
# We filter out feeds that already have the status so that the
49-
# update count reflects the number of feeds that actually
50-
# changed status.
51-
Feed.status != text("'%s'::status" % status),
52-
service_date_conditions,
53-
]
49+
def get_filters(status: str):
50+
filters = [
51+
Feed.id == latest_dataset_subq.c.feed_id,
52+
Feed.status != text("'deprecated'::status"),
53+
Feed.status != text("'development'::status"),
54+
# We filter out feeds that already have the status so that the
55+
# update count reflects the number of feeds that actually
56+
# changed status.
57+
Feed.status != text("'%s'::status" % status),
58+
service_date_conditions,
59+
]
5460

55-
if len(stable_feed_ids) > 0:
56-
filters.append(Feed.stable_feed_id.in_(stable_feed_ids))
61+
if len(stable_feed_ids) > 0:
62+
filters.append(Feed.stable_feed_id.in_(stable_feed_ids))
5763

5864
for service_date_conditions, status in status_conditions:
5965
diff_counts[status] = (
6066
session.query(Feed)
61-
.filter(*filters)
67+
.filter(*get_filters(status))
6268
.update({Feed.status: status}, synchronize_session=False)
6369
)
6470
except Exception as e:

functions-python/update_feed_status/src/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import functions_framework
33
from shared.helpers.logger import Logger
44
from shared.helpers.feed_status import update_feed_statuses_query
5-
from typing import TYPE_CHECKING
65
from shared.database.database import with_db_session
76

8-
if TYPE_CHECKING:
9-
from sqlalchemy.orm import Session
10-
117
logging.basicConfig(level=logging.INFO)
128

9+
1310
@with_db_session
1411
@functions_framework.http
1512
def update_feed_status(_, db_session):

0 commit comments

Comments
 (0)