Skip to content

Commit 1e1597e

Browse files
[DPE-7603][DPE-6990] Fix check in relation initialisation (#1054)
* Fix check in relation initialisation Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Revert changes to poetry.lock Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Fix linting Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent d1822d9 commit 1e1597e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/relations/postgresql_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
8181
Generate password and handle user and database creation for the related application.
8282
"""
8383
# Check for some conditions before trying to access the PostgreSQL instance.
84-
if not self.charm.is_cluster_initialised or not self.charm._patroni.member_started:
84+
if not self.charm.is_cluster_initialised or not self.charm._patroni.primary_endpoint_ready:
8585
logger.debug(
8686
"Deferring on_database_requested: Cluster must be initialized before database can be requested"
8787
)

tests/unit/test_postgresql_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ def test_on_database_requested(harness):
7878
patch("charm.PostgresqlOperatorCharm.update_config"),
7979
patch.object(PostgresqlOperatorCharm, "postgresql", Mock()) as postgresql_mock,
8080
patch.object(EventBase, "defer") as _defer,
81-
patch("charm.Patroni.member_started", new_callable=PropertyMock) as _member_started,
81+
patch(
82+
"charm.Patroni.primary_endpoint_ready", new_callable=PropertyMock
83+
) as _primary_endpoint_ready,
8284
patch(
8385
"relations.postgresql_provider.new_password", return_value="test-password"
8486
) as _new_password,
8587
):
8688
rel_id = harness.model.get_relation(RELATION_NAME).id
8789
# Set some side effects to test multiple situations.
88-
_member_started.side_effect = [False, True, True, True, True, True]
90+
_primary_endpoint_ready.side_effect = [False, True, True, True, True, True]
8991
postgresql_mock.create_user = PropertyMock(
9092
side_effect=[None, PostgreSQLCreateUserError, None, None]
9193
)

0 commit comments

Comments
 (0)