Skip to content

Commit d5e8cd7

Browse files
author
Jacob Pan
committed
Change Conn Name to Prevent Outer Scope and Typing
Connection variable for changing to WAL mode was shadowing the other connection variables inside functions so changed it to make it distinct. Also added typing corrections. BCK-7002-3
1 parent 0913b4b commit d5e8cd7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

alerts_backend/python/app.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Query alert information from AeroAPI and present it to a frontend service"""
22
import os
33
from datetime import datetime
4-
from typing import Dict, Any, Union
4+
from typing import Dict, Any, Tuple
55

66
import json
77
import requests
@@ -26,9 +26,9 @@
2626
"sqlite+pysqlite:////var/db/aeroapi_alerts/aeroapi_alerts.db", echo=False, future=True
2727
)
2828
# Set journal_mode to WAL to enable reading and writing concurrently
29-
with engine.connect() as conn:
30-
conn.exec_driver_sql("PRAGMA journal_mode=WAL")
31-
conn.commit()
29+
with engine.connect() as conn_wal:
30+
conn_wal.exec_driver_sql("PRAGMA journal_mode=WAL")
31+
conn_wal.commit()
3232

3333
# Define tables and metadata to insert and create
3434
metadata_obj = MetaData()
@@ -86,7 +86,7 @@ def create_tables():
8686
raise e
8787

8888

89-
def insert_into_table(data_to_insert: Dict[str, Union[str, int, bool]], table: Table) -> int:
89+
def insert_into_table(data_to_insert: Dict[str, Any], table: Table) -> int:
9090
"""
9191
Insert object into the database based off of the table.
9292
Assumes data_to_insert has values for all the keys
@@ -107,7 +107,7 @@ def insert_into_table(data_to_insert: Dict[str, Union[str, int, bool]], table: T
107107

108108

109109
@app.route("/post", methods=["POST"])
110-
def handle_alert() -> (Response, int):
110+
def handle_alert() -> Tuple[Response, int]:
111111
"""
112112
Function to receive AeroAPI POST requests. Filters the request
113113
and puts the necessary data into the SQL database.
@@ -117,9 +117,9 @@ def handle_alert() -> (Response, int):
117117
r_title: str
118118
r_detail: str
119119
r_status: int
120-
data: Dict[Any] = request.json
120+
data: Dict[str, Any] = request.json
121121
# Process data by getting things needed
122-
processed_data: Dict[Any]
122+
processed_data: Dict[str, Any]
123123
try:
124124
processed_data = {
125125
"long_description": data["long_description"],
@@ -169,7 +169,7 @@ def create_alert() -> Response:
169169
r_description: str = ''
170170
# Process json
171171
content_type = request.headers.get("Content-Type")
172-
data: Dict[Any]
172+
data: Dict[str, Any]
173173

174174
if content_type != "application/json":
175175
r_description = "Invalid content sent"

0 commit comments

Comments
 (0)