From 7285775f54a3ef827956d1936694354aa1f48f0c Mon Sep 17 00:00:00 2001 From: Guillaume Boutry Date: Tue, 6 Feb 2024 19:00:35 +0100 Subject: [PATCH] Read only provider side of database relation Since upgrade of mysql relation (and secrets), only the application's leader can lead the whole relation databag. Non-leader requiring units are only allowed to read the provider side of the relation and their own unit's. Change-Id: Iee073d654cabfbdefc817ea7c0207f3f28c457ac --- ops-sunbeam/ops_sunbeam/relation_handlers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ops-sunbeam/ops_sunbeam/relation_handlers.py b/ops-sunbeam/ops_sunbeam/relation_handlers.py index 127214e9..c50526f6 100644 --- a/ops-sunbeam/ops_sunbeam/relation_handlers.py +++ b/ops-sunbeam/ops_sunbeam/relation_handlers.py @@ -332,10 +332,11 @@ class DBHandler(RelationHandler): def get_relation_data(self) -> dict: """Load the data from the relation for consumption in the handler.""" - if len(self.interface.relations) > 0: - return self.interface.relations[0].data[ - self.interface.relations[0].app - ] + # there is at most one relation for a database + for relation in self.model.relations[self.relation_name]: + if relation.app is None: + continue + return relation.data[relation.app] return {} @property