Skip to content

Commit de10634

Browse files
committed
Revert to see if changes really necessary
1 parent 201bd2d commit de10634

File tree

3 files changed

+4
-31
lines changed

3 files changed

+4
-31
lines changed

app/application.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
from .gino import Gino, GinoEngine
1010
from .settings.globals import GLOBALS
1111

12-
# Explicitly register the gino asyncpg dialect with SQLAlchemy
13-
# This ensures it's available before any database connections are attempted
14-
try:
15-
from sqlalchemy.dialects import registry
16-
import gino.dialects.asyncpg
17-
registry.register("asyncpg", "gino.dialects.asyncpg", "AsyncpgDialect")
18-
registry.register("postgresql.asyncpg", "gino.dialects.asyncpg", "AsyncpgDialect")
19-
except Exception:
20-
# If registration fails, the normal import should still work
21-
pass
22-
2312
READ_ENGINE: Optional[GinoEngine] = None
2413
SessionLocal: Optional[Session] = None
2514
Base = declarative_base()
@@ -31,7 +20,6 @@
3120

3221
db = Gino(
3322
app,
34-
driver="asyncpg",
3523
host=GLOBALS.database_config.host,
3624
port=GLOBALS.database_config.port,
3725
user=GLOBALS.database_config.username,
@@ -53,20 +41,8 @@ def get_synchronous_db() -> Iterator[Session]:
5341
raise RuntimeError("No database url set.")
5442

5543
if SessionLocal is None:
56-
# Create a synchronous database URL using psycopg2 instead of asyncpg
57-
# asyncpg only works with async engines, not synchronous ones
58-
from sqlalchemy.engine.url import URL
59-
60-
db_config = GLOBALS.database_config
61-
sync_url = URL(
62-
drivername="postgresql+psycopg2",
63-
username=db_config.username,
64-
password=str(db_config.password) if db_config.password else None,
65-
host=db_config.host,
66-
port=db_config.port,
67-
database=db_config.database,
68-
)
69-
engine = create_engine(sync_url, pool_size=5, max_overflow=0)
44+
db_conn = GLOBALS.database_config.url
45+
engine = create_engine(db_conn, pool_size=5, max_overflow=0)
7046
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
7147

7248
synchronous_db: Optional[Session] = None

app/gino.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
from starlette.exceptions import HTTPException
1818
from starlette.types import Receive, Scope, Send
1919

20-
# Explicitly import the asyncpg dialect to ensure it's registered with SQLAlchemy
21-
import gino.dialects.asyncpg # noqa: F401
22-
2320
logger = logging.getLogger("gino.ext.starlette")
2421

2522

app/settings/globals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def set_database_config(cls, v, values, **kwarg) -> DatabaseURL:
134134
if db_reader_secret:
135135
secret = json.loads(db_reader_secret)
136136
v = DatabaseURL(
137-
drivername="asyncpg",
137+
drivername="postgresql",
138138
username=secret["username"],
139139
password=secret["password"],
140140
host=secret["host"],
@@ -143,7 +143,7 @@ def set_database_config(cls, v, values, **kwarg) -> DatabaseURL:
143143
)
144144
else:
145145
v = DatabaseURL(
146-
drivername="asyncpg",
146+
drivername="postgresql",
147147
username=input.get("reader_username"),
148148
password=input.get("reader_password"),
149149
host=input.get("reader_host"),

0 commit comments

Comments
 (0)