Skip to content

Commit

Permalink
Postgres: retry connection if unsupported options parameter (#2176)
Browse files Browse the repository at this point in the history
Co-authored-by: Milan Lukac <[email protected]>
  • Loading branch information
RekunDzmitry and m1n0 authored Feb 20, 2025
1 parent 405054b commit b4be075
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions soda/postgres/soda/data_sources/postgres_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,30 @@ def connect(self):
self.logs.debug(
f'Postgres connection properties: host="{self.host}", port="{self.port}", database="{self.database}", user="{self.username}", options="{options}", connection_timeout="{self.connection_timeout}"'
)
self.connection = psycopg2.connect(
user=self.username,
password=self.password,
host=self.host,
port=self.port,
connect_timeout=self.connection_timeout,
database=self.database,
options=options,
sslmode=self.sslmode,
)
try:
self.connection = psycopg2.connect(
user=self.username,
password=self.password,
host=self.host,
port=self.port,
connect_timeout=self.connection_timeout,
database=self.database,
options=options,
sslmode=self.sslmode,
)
except psycopg2.OperationalError as e:
if "unsupported startup parameter: options" in str(e):
self.connection = psycopg2.connect(
user=self.username,
password=self.password,
host=self.host,
port=self.port,
connect_timeout=self.connection_timeout,
database=self.database,
sslmode=self.sslmode,
)
else:
raise e
else:
raise ConnectionError(f"Invalid postgres connection properties: invalid host: {self.host}")
return self.connection
Expand Down

0 comments on commit b4be075

Please sign in to comment.