diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 1c73959a37..54453a3623 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -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" @@ -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" @@ -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() diff --git a/src/relations/postgresql_provider.py b/src/relations/postgresql_provider.py index 1734d4f047..844da3b6f9 100644 --- a/src/relations/postgresql_provider.py +++ b/src/relations/postgresql_provider.py @@ -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") self.charm.unit_peer_data.update({ "pg_hba_needs_update_timestamp": str(datetime.now()) })