Skip to content

Commit bbd596b

Browse files
authored
Merge pull request #973 from cmu-delphi/v4-schema-revisions-release-prep-flaskalchemy
Build and image with new Flask and SQLAlchemy
2 parents 2e49339 + fd7b815 commit bbd596b

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

devops/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ WORKDIR /src
33
COPY . /src
44
RUN npm ci && npm run build
55

6-
FROM tiangolo/meinheld-gunicorn:python3.7
6+
FROM tiangolo/meinheld-gunicorn:python3.8
77
LABEL org.opencontainers.image.source=https://github.com/cmu-delphi/delphi-epidata
88
# use delphi's timezome
99
RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime
1010

11-
COPY requirements.txt /app
12-
RUN pip install --no-cache-dir -r requirements.txt
11+
COPY requirements.txt /app/requirements_also.txt
12+
RUN pip install --no-cache-dir -r /tmp/requirements.txt -r requirements_also.txt
13+
# the file /tmp/requirements.txt is created in the parent docker definition. (see:
14+
# https://github.com/tiangolo/meinheld-gunicorn-docker/blob/master/docker-images/python3.8.dockerfile#L5 )
15+
# this combined requirements installation ensures all version constrants are accounted for.
1316

1417
# disable python stdout buffering
1518
ENV PYTHONUNBUFFERED 1

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
itsdangerous<2.1
22
jinja2==3.0.3
3-
werkzeug<2.1
4-
Flask==1.1.2
5-
SQLAlchemy==1.3.22
3+
werkzeug==2.2.2
4+
Flask==2.2.2
5+
SQLAlchemy==1.4.40
66
mysqlclient==2.0.2
77
python-dotenv==0.15.0
88
orjson==3.4.7

src/server/_config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111
MAX_COMPATIBILITY_RESULTS = int(3650)
1212

1313
SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///test.db")
14-
SQLALCHEMY_ENGINE_OPTIONS = json.loads(os.environ.get("SQLALCHEMY_ENGINE_OPTIONS", "{}"))
14+
15+
# defaults
16+
SQLALCHEMY_ENGINE_OPTIONS = {
17+
"pool_pre_ping": True, # enable ping test for validity of recycled pool connections on connect() calls
18+
"pool_recycle": 5 # seconds after which a recycled pool connection is considered invalid
19+
}
20+
# update with overrides of defaults or additions from external configs
21+
SQLALCHEMY_ENGINE_OPTIONS.update(
22+
json.loads(os.environ.get("SQLALCHEMY_ENGINE_OPTIONS", "{}")))
23+
1524
SECRET = os.environ.get("FLASK_SECRET", "secret")
1625
URL_PREFIX = os.environ.get("FLASK_PREFIX", "/")
1726

src/server/_query.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515

1616
from sqlalchemy import text
17-
from sqlalchemy.engine import RowProxy
17+
from sqlalchemy.engine import Row
1818

1919
from ._common import db, app
2020
from ._db import metadata
@@ -197,7 +197,7 @@ def filter_pair(pair: TimePair, i) -> str:
197197

198198

199199
def parse_row(
200-
row: RowProxy,
200+
row: Row,
201201
fields_string: Optional[Sequence[str]] = None,
202202
fields_int: Optional[Sequence[str]] = None,
203203
fields_float: Optional[Sequence[str]] = None,
@@ -245,7 +245,7 @@ def run_query(p: APrinter, query_tuple: Tuple[str, Dict[str, Any]]):
245245
return db.execution_options(stream_results=True).execute(full_query, **params)
246246

247247

248-
def _identity_transform(row: Dict[str, Any], _: RowProxy) -> Dict[str, Any]:
248+
def _identity_transform(row: Dict[str, Any], _: Row) -> Dict[str, Any]:
249249
"""
250250
identity transform
251251
"""
@@ -257,7 +257,7 @@ def execute_queries(
257257
fields_string: Sequence[str],
258258
fields_int: Sequence[str],
259259
fields_float: Sequence[str],
260-
transform: Callable[[Dict[str, Any], RowProxy], Dict[str, Any]] = _identity_transform,
260+
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
261261
):
262262
"""
263263
execute the given queries and return the response to send them
@@ -317,7 +317,7 @@ def execute_query(
317317
fields_string: Sequence[str],
318318
fields_int: Sequence[str],
319319
fields_float: Sequence[str],
320-
transform: Callable[[Dict[str, Any], RowProxy], Dict[str, Any]] = _identity_transform,
320+
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
321321
):
322322
"""
323323
execute the given query and return the response to send it

0 commit comments

Comments
 (0)