Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f48ae14
fix: add pg8000 graceful shutdown on Cloud Run scale-down
panish16 May 26, 2026
00a1f4e
fix: bump cloud-sql-connector lock to v0.2.3 and use inline pg8000 sh…
panish16 May 27, 2026
fbe862e
fix: correct cloud-sql-connector lock to v0.2.3 with correct remote hash
panish16 May 27, 2026
1e9d07a
fix: move imports to module level and rename _InterfaceError in legal…
panish16 May 28, 2026
31b3db1
fix: suppress N813 on pg8000 InterfaceError import alias in legal-api
panish16 May 28, 2026
37c3fcf
fix: simplify queue service pg8000 setup, remove unnecessary DBConfig…
panish16 Jun 2, 2026
2f1deed
fix: move DBConfig engine options to config.py and use shared pg8000 …
panish16 Jun 2, 2026
e1021df
fix: keep local pg8000 shutdown in legal-api until python3.9 branch i…
panish16 Jun 2, 2026
25036ee
fix: use setup_pg8000_close_event_listener in legal-api and bump lock…
panish16 Jun 2, 2026
d4bc420
fix: revert legal-api to local pg8000 shutdown until sbc-connect-comm…
panish16 Jun 2, 2026
44281ce
fix: update codecov.yaml with correct business-* flag names and sourc…
panish16 Jun 2, 2026
66b34b3
fix: add pytest/coverage config to business-pay, emailer, digital-cre…
panish16 Jun 2, 2026
00a5875
revert: restore codecov.yaml to main (unrelated to pg8000 shutdown fix)
panish16 Jun 2, 2026
1092b63
merge: sync with upstream/main
panish16 Jun 3, 2026
1b6b37c
fix: use setup_pg8000_close_event_listener from cloud-sql-connector i…
panish16 Jun 3, 2026
83138fd
merge: sync with bcgov feature branch, keep shared pg8000 listener fr…
panish16 Jun 3, 2026
34ba30e
fix: revert legal-api to local pg8000 shutdown and fix poetry.lock ref
panish16 Jun 3, 2026
4af4e1a
fix: use setup_pg8000_close_event_listener from cloud-sql-connector p…
panish16 Jun 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions legal-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 2 additions & 26 deletions legal-api/src/legal_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@

This module is the API for the Legal Entity system.
"""
import logging
import os
from typing import Optional

from cloud_sql_connector import setup_pg8000_close_event_listener
from flask import Flask, jsonify
from registry_schemas import __version__ as registry_schemas_version
from registry_schemas.flask import SchemaServices
from sqlalchemy import event

from legal_api import config, models
from legal_api.models import db
Expand All @@ -63,29 +62,6 @@
setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.conf")) # important to do this first


def _setup_pg8000_graceful_shutdown(engine) -> None:
"""Suppress pg8000 InterfaceError on connection close during Cloud Run scale-down."""
try:
from pg8000.exceptions import InterfaceError as _interface_error # noqa: N813
except ImportError:
_interface_error = None

@event.listens_for(engine, "connect")
def on_connect(dbapi_conn, _connection_record):
orig_close = dbapi_conn.close

def safe_close():
try:
orig_close()
except Exception as exc:
if _interface_error and isinstance(exc, _interface_error):
logging.getLogger(__name__).debug("Suppressed pg8000 InterfaceError on teardown.")
else:
raise

dbapi_conn.close = safe_close


def create_app(run_mode: Optional[str] = None, **kwargs) -> Flask:
"""Return a configured Flask App using the Factory method."""
run_mode = run_mode or os.getenv("RUN_MODE", "production")
Expand All @@ -108,7 +84,7 @@ def create_app(run_mode: Optional[str] = None, **kwargs) -> Flask:
with app.app_context(): # db require app context
digital_credentials.init_app(app)
if app.config.get("CLOUDSQL_INSTANCE_CONNECTION_NAME"): # pragma: no cover
_setup_pg8000_graceful_shutdown(db.engine)
setup_pg8000_close_event_listener(db.engine)

cache.init_app(app)

Expand Down