Skip to content

Commit 7a538a0

Browse files
DPE-7726: Fix exception on update-status. PostgreSQLUndefinedHostError: Host not set.
Exception: > 2025-08-19 20:49:40 DEBUG unit.postgresql/2.juju-log server.go:406 cluster:API get_patroni_health: <Response [200]> (0.057417) > 2025-08-19 20:49:40 DEBUG unit.postgresql/2.juju-log server.go:406 cluster:API cluster_status: [{'name': 'postgresql-0', 'role': 'leader', 'state': 'running', 'api_url': 'https://10.182.246.123:8008/patroni', 'host': '10.182.246.123', 'port': 5432, 'timeline': 1}, {'name': 'postgresql-1', 'role': 'sync_standby', 'state': 'running', 'api_url': 'https://10.182.246.163:8008/patroni', 'host': '10.182.246.163', 'port': 5432, 'timeline': 1, 'lag': 0}, {'name': 'postgresql-2', 'role': 'sync_standby', 'state': 'running', 'api_url': 'https://10.182.246.246:8008/patroni', 'host': '10.182.246.246', 'port': 5432, 'timeline': 1, 'lag': 0}] > 2025-08-19 20:49:40 DEBUG unit.postgresql/2.juju-log server.go:406 __main__:Early exit primary_endpoint: Primary IP not in cached peer list > 2025-08-19 20:49:40 ERROR unit.postgresql/2.juju-log server.go:406 root:Uncaught exception while in charm code: > Traceback (most recent call last): > File "/var/lib/juju/agents/unit-postgresql-2/charm/src/charm.py", line 2736, in <module> > main(PostgresqlOperatorCharm) > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/__init__.py", line 356, in __call__ > return _main.main(charm_class=charm_class, use_juju_for_storage=use_juju_for_storage) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 502, in main > manager.run() > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 486, in run > self._emit() > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 421, in _emit > self._emit_charm_event(self.dispatcher.event_name) > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 465, in _emit_charm_event > event_to_emit.emit(*args, **kwargs) > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 351, in emit > framework._emit(event) > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 924, in _emit > self._reemit(event_path) > File "/var/lib/juju/agents/unit-postgresql-2/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 1030, in _reemit > custom_handler(event) > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1116, in wrapped_function > return callable(*args, **kwargs) # type: ignore > ^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/src/charm.py", line 1942, in _on_update_status > self.postgresql_client_relation.oversee_users() > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1116, in wrapped_function > return callable(*args, **kwargs) # type: ignore > ^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/src/relations/postgresql_provider.py", line 172, in oversee_users > user for user in self.charm.postgresql.list_users() if user.startswith("relation-") > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1116, in wrapped_function > return callable(*args, **kwargs) # type: ignore > ^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/postgresql_k8s/v1/postgresql.py", line 959, in list_users > with self._connect_to_database( > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1116, in wrapped_function > return callable(*args, **kwargs) # type: ignore > ^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/var/lib/juju/agents/unit-postgresql-2/charm/lib/charms/postgresql_k8s/v1/postgresql.py", line 273, in _connect_to_database > raise PostgreSQLUndefinedHostError("Host not set") > charms.postgresql_k8s.v1.postgresql.PostgreSQLUndefinedHostError: Host not set > 2025-08-19 20:49:40 ERROR juju.worker.uniter.operation runhook.go:180 hook "update-status" (via hook dispatching script: dispatch) failed: exit status 1
1 parent 176391e commit 7a538a0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/relations/postgresql_provider.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
PostgreSQLCreateUserError,
2121
PostgreSQLDeleteUserError,
2222
PostgreSQLListUsersError,
23+
PostgreSQLUndefinedHostError,
24+
PostgreSQLUndefinedPasswordError,
2325
)
2426
from ops.charm import RelationBrokenEvent
2527
from ops.framework import Object
@@ -171,7 +173,12 @@ def oversee_users(self) -> None:
171173
database_users = {
172174
user for user in self.charm.postgresql.list_users() if user.startswith("relation-")
173175
}
174-
except PostgreSQLListUsersError:
176+
except (
177+
PostgreSQLListUsersError,
178+
PostgreSQLUndefinedHostError,
179+
PostgreSQLUndefinedPasswordError,
180+
) as e:
181+
logger.error("Early-exit, failed to oversee users: %r", e)
175182
return
176183

177184
# Retrieve the users from the active relations.

0 commit comments

Comments
 (0)