@@ -606,74 +606,58 @@ def pool_config_dict(self) -> dict[str, Any]:
606606
607607 async def _create_pool (self ) -> "AsyncConnectionPool" :
608608 """Create the actual async connection pool."""
609- logger .info ("Creating async Psycopg connection pool" , extra = {"adapter" : "psycopg" })
610609
611- try :
612- # Get all config (creates a new dict)
613- all_config = self .pool_config_dict .copy ()
610+ # Get all config (creates a new dict)
611+ all_config = self .pool_config_dict .copy ()
612+
613+ # Separate pool-specific parameters that AsyncConnectionPool accepts directly
614+ pool_params = {
615+ "min_size" : all_config .pop ("min_size" , 4 ),
616+ "max_size" : all_config .pop ("max_size" , None ),
617+ "name" : all_config .pop ("name" , None ),
618+ "timeout" : all_config .pop ("timeout" , 30.0 ),
619+ "max_waiting" : all_config .pop ("max_waiting" , 0 ),
620+ "max_lifetime" : all_config .pop ("max_lifetime" , 3600.0 ),
621+ "max_idle" : all_config .pop ("max_idle" , 600.0 ),
622+ "reconnect_timeout" : all_config .pop ("reconnect_timeout" , 300.0 ),
623+ "num_workers" : all_config .pop ("num_workers" , 3 ),
624+ }
614625
615- # Separate pool-specific parameters that AsyncConnectionPool accepts directly
616- pool_params = {
617- "min_size" : all_config .pop ("min_size" , 4 ),
618- "max_size" : all_config .pop ("max_size" , None ),
619- "name" : all_config .pop ("name" , None ),
620- "timeout" : all_config .pop ("timeout" , 30.0 ),
621- "max_waiting" : all_config .pop ("max_waiting" , 0 ),
622- "max_lifetime" : all_config .pop ("max_lifetime" , 3600.0 ),
623- "max_idle" : all_config .pop ("max_idle" , 600.0 ),
624- "reconnect_timeout" : all_config .pop ("reconnect_timeout" , 300.0 ),
625- "num_workers" : all_config .pop ("num_workers" , 3 ),
626- }
626+ # Create a configure callback to set row_factory
627+ async def configure_connection (conn : "PsycopgAsyncConnection" ) -> None :
628+ # Set DictRow as the row factory
629+ conn .row_factory = dict_row
627630
628- # Create a configure callback to set row_factory
629- async def configure_connection (conn : "PsycopgAsyncConnection" ) -> None :
630- # Set DictRow as the row factory
631- conn .row_factory = dict_row
631+ pool_params ["configure" ] = all_config .pop ("configure" , configure_connection )
632632
633- pool_params ["configure" ] = all_config .pop ("configure" , configure_connection )
633+ # Remove None values from pool_params
634+ pool_params = {k : v for k , v in pool_params .items () if v is not None }
634635
635- # Remove None values from pool_params
636- pool_params = {k : v for k , v in pool_params .items () if v is not None }
636+ # Handle conninfo vs individual connection parameters
637+ conninfo = all_config .pop ("conninfo" , None )
638+ if conninfo :
639+ # If conninfo is provided, use it directly
640+ # Don't pass kwargs when using conninfo string
641+ pool = AsyncConnectionPool (conninfo , open = False , ** pool_params )
642+ else :
643+ # Otherwise, pass connection parameters via kwargs
644+ # Remove any non-connection parameters
645+ # row_factory is already popped out earlier
646+ all_config .pop ("row_factory" , None )
647+ # Remove pool-specific settings that may have been left
648+ all_config .pop ("kwargs" , None )
649+ pool = AsyncConnectionPool ("" , kwargs = all_config , open = False , ** pool_params )
637650
638- # Handle conninfo vs individual connection parameters
639- conninfo = all_config .pop ("conninfo" , None )
640- if conninfo :
641- # If conninfo is provided, use it directly
642- # Don't pass kwargs when using conninfo string
643- pool = AsyncConnectionPool (conninfo , ** pool_params )
644- else :
645- # Otherwise, pass connection parameters via kwargs
646- # Remove any non-connection parameters
647- # row_factory is already popped out earlier
648- all_config .pop ("row_factory" , None )
649- # Remove pool-specific settings that may have been left
650- all_config .pop ("kwargs" , None )
651- pool = AsyncConnectionPool ("" , kwargs = all_config , ** pool_params )
651+ await pool .open ()
652652
653- await pool .open ()
654- logger .info ("Async Psycopg connection pool created successfully" , extra = {"adapter" : "psycopg" })
655- except Exception as e :
656- logger .exception (
657- "Failed to create async Psycopg connection pool" , extra = {"adapter" : "psycopg" , "error" : str (e )}
658- )
659- raise
660653 return pool
661654
662655 async def _close_pool (self ) -> None :
663656 """Close the actual async connection pool."""
664657 if not self .pool_instance :
665658 return
666659
667- logger .info ("Closing async Psycopg connection pool" , extra = {"adapter" : "psycopg" })
668-
669- try :
670- await self .pool_instance .close ()
671- logger .info ("Async Psycopg connection pool closed successfully" , extra = {"adapter" : "psycopg" })
672- except Exception as e :
673- logger .exception (
674- "Failed to close async Psycopg connection pool" , extra = {"adapter" : "psycopg" , "error" : str (e )}
675- )
676- raise
660+ await self .pool_instance .close ()
677661
678662 async def create_connection (self ) -> "PsycopgAsyncConnection" : # pyright: ignore
679663 """Create a single async connection (not from pool).
0 commit comments