Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

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

# Groups to distinguish HBA access
ACCESS_GROUP_IDENTITY = "identity_access"
Expand Down Expand Up @@ -780,6 +780,7 @@ def list_valid_privileges_and_roles(self) -> Tuple[Set[str], Set[str]]:
def set_up_database(self) -> None:
"""Set up postgres database with the right permissions."""
connection = None
cursor = None
try:
with self._connect_to_database(
database="template1"
Expand Down Expand Up @@ -879,6 +880,8 @@ def set_up_database(self) -> None:
logger.error(f"Failed to set up databases: {e}")
raise PostgreSQLDatabasesSetupError() from e
finally:
if cursor is not None:
cursor.close()
if connection is not None:
connection.close()

Expand Down
3 changes: 2 additions & 1 deletion src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
try:
for attempt in Retrying(stop=stop_after_attempt(3), wait=wait_fixed(1)):
with attempt:
self.charm.postgresql.is_user_in_hba(user)
if not self.charm.postgresql.is_user_in_hba(user):
raise Exception("pg_hba not ready")
Comment on lines +151 to +152
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the output of the function and retry if not true.

self.charm.unit_peer_data.update({
"pg_hba_needs_update_timestamp": str(datetime.now())
})
Expand Down