Skip to content

Commit e72e6a6

Browse files
committed
✨ Refactor: Deprecate connect_to_db function and recommend postgres_lifespan for database connection management
1 parent 4096344 commit e72e6a6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/service-library/src/servicelib/db_async_engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async def connect_to_db(app: FastAPI, settings: PostgresSettings) -> None:
2222
"The 'connect_to_db' function is deprecated and will be removed in a future release. "
2323
"Please use 'postgres_lifespan' instead for managing the database connection lifecycle.",
2424
DeprecationWarning,
25+
stacklevel=2,
2526
)
2627
with log_context(
2728
_logger, logging.DEBUG, f"connection to db {settings.dsn_with_async_sqlalchemy}"

packages/service-library/src/servicelib/fastapi/db_asyncpg_engine.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import warnings
23

34
from fastapi import FastAPI
45
from settings_library.postgres import PostgresSettings
@@ -14,6 +15,13 @@
1415

1516

1617
async def connect_to_db(app: FastAPI, settings: PostgresSettings) -> None:
18+
warnings.warn(
19+
"The 'connect_to_db' function is deprecated and will be removed in a future release. "
20+
"Please use 'postgres_lifespan' instead for managing the database connection lifecycle.",
21+
DeprecationWarning,
22+
stacklevel=2,
23+
)
24+
1725
with log_context(
1826
_logger,
1927
logging.DEBUG,

0 commit comments

Comments
 (0)