Skip to content

Commit

Permalink
Update charm libs
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Jul 26, 2024
1 parent e226c9a commit ee8d6a1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ops.model import Relation
from psycopg2 import sql
from psycopg2.sql import Composed
from tenacity import Retrying, stop_after_attempt, wait_fixed

# The unique Charmhub library identifier, never change it
LIBID = "24ee217a54e840a598ff21a079c3e678"
Expand All @@ -37,7 +36,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 31
LIBPATCH = 33

INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"

Expand Down Expand Up @@ -129,12 +128,10 @@ def _connect_to_database(
psycopg2 connection object.
"""
host = database_host if database_host is not None else self.primary_host
for attempt in Retrying(stop=stop_after_attempt(10), wait=wait_fixed(3), reraise=True):
with attempt:
connection = psycopg2.connect(
f"dbname='{database if database else self.database}' user='{self.user}' host='{host}'"
f"password='{self.password}' connect_timeout=1"
)
connection = psycopg2.connect(
f"dbname='{database if database else self.database}' user='{self.user}' host='{host}'"
f"password='{self.password}' connect_timeout=1"
)
connection.autocommit = True
return connection

Expand Down Expand Up @@ -330,6 +327,8 @@ def enable_disable_extensions(self, extensions: Dict[str, bool], database: str =
)
except psycopg2.errors.UniqueViolation:
pass
except psycopg2.errors.DependentObjectsStillExist:
raise
except psycopg2.Error:
raise PostgreSQLEnableDisableExtensionError()
finally:
Expand Down

0 comments on commit ee8d6a1

Please sign in to comment.