]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
open AsyncConnectionPool outside constructor 12540/head
authorchrispy <chrispy@synopsys.com>
Sun, 4 May 2025 13:40:22 +0000 (09:40 -0400)
committerchrispy <chrispy@synopsys.com>
Sun, 4 May 2025 13:40:22 +0000 (09:40 -0400)
Signed-off-by: chrispy <chrispy@synopsys.com>
lib/sqlalchemy/dialects/postgresql/psycopg.py

index 5c8f1030d7e9516bcc6ef3403766cd4c913b8ea3..5df240399238cece6eb9e89b5d794f5e714ba5bf 100644 (file)
@@ -148,17 +148,18 @@ Here is an example that uses ``psycopg_pool.AsyncConnectionPool``::
             min_size=1,   # Minimum pool size
             max_size=5,   # Maximum pool size
             max_idle=60,  # Maximum idle time (seconds) for unused pool connections
+            open=False,   # See comment below
         )
 
-        # Define a callable that awaits a connection
-        async def get_connection():
-            return await mypool.getconn()
+        # Must explicitly open AsyncConnectionPool outside constructor
+        # (https://www.psycopg.org/psycopg3/docs/advanced/pool.html#other-ways-to-create-a-pool)
+        await mypool.open()
 
         # Create an engine that uses the connection pool to get a connection
         engine = create_async_engine(
             url="postgresql+psycopg://",   # Only need the dialect now
             poolclass=NullPool,            # Disable SQLAlchemy's default connection pool
-            async_creator=get_connection,  # Use Psycopg 3 connection pool to obtain connections
+            async_creator=mypool.getconn,  # Use Psycopg 3 connection pool to obtain connections
         )
 
 The resulting engine may then be used normally. Internally, Psycopg 3 handles