File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212def connect_pg (config : PostgreSQLDatabaseConfiguration ) -> Any :
1313 """Initialize connection to PostgreSQL database."""
1414 logger .info ("Connecting to PostgreSQL storage" )
15- connection = psycopg2 .connect (
16- host = config .host ,
17- port = config .port ,
18- user = config .user ,
19- password = config .password .get_secret_value (),
20- dbname = config .db ,
21- sslmode = config .ssl_mode ,
22- # sslrootcert=config.ca_cert_path,
23- gssencmode = config .gss_encmode ,
24- )
25- if connection is not None :
26- connection .autocommit = True
27- return connection
15+ try :
16+ connection = psycopg2 .connect (
17+ host = config .host ,
18+ port = config .port ,
19+ user = config .user ,
20+ password = config .password .get_secret_value (),
21+ dbname = config .db ,
22+ sslmode = config .ssl_mode ,
23+ # sslrootcert=config.ca_cert_path,
24+ gssencmode = config .gss_encmode ,
25+ )
26+ if connection is not None :
27+ connection .autocommit = True
28+ return connection
29+ except psycopg2 .Error as e :
30+ logger .exception ("Error connecting to PostgreSQL database:\n %s" , e )
31+ raise
Original file line number Diff line number Diff line change @@ -17,10 +17,9 @@ def connect_sqlite(config: SQLiteDatabaseConfiguration) -> Any:
1717 connection = None
1818 try :
1919 connection = sqlite3 .connect (database = config .db_path )
20- except sqlite3 .Error as e :
2120 if connection is not None :
22- connection .close ()
21+ connection .autocommit = True
22+ return connection
23+ except sqlite3 .Error as e :
2324 logger .exception ("Error initializing SQLite cache:\n %s" , e )
2425 raise
25- connection .autocommit = True
26- return connection
You can’t perform that action at this time.
0 commit comments