@@ -320,7 +320,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
320
320
321
321
# Increment this PATCH version before using `charmcraft publish-lib` or reset
322
322
# to 0 if you are raising the major API version
323
- LIBPATCH = 23
323
+ LIBPATCH = 24
324
324
325
325
PYDEPS = ["ops>=2.0.0" ]
326
326
@@ -526,7 +526,16 @@ def get_content(self) -> Dict[str, str]:
526
526
"""Getting cached secret content."""
527
527
if not self ._secret_content :
528
528
if self .meta :
529
- self ._secret_content = self .meta .get_content ()
529
+ try :
530
+ self ._secret_content = self .meta .get_content (refresh = True )
531
+ except (ValueError , ModelError ) as err :
532
+ # https://bugs.launchpad.net/juju/+bug/2042596
533
+ # Only triggered when 'refresh' is set
534
+ msg = "ERROR either URI or label should be used for getting an owned secret but not both"
535
+ if isinstance (err , ModelError ) and msg not in str (err ):
536
+ raise
537
+ # Due to: ValueError: Secret owner cannot use refresh=True
538
+ self ._secret_content = self .meta .get_content ()
530
539
return self ._secret_content
531
540
532
541
def set_content (self , content : Dict [str , str ]) -> None :
@@ -1085,7 +1094,7 @@ def _delete_relation_secret(
1085
1094
secret = self ._get_relation_secret (relation .id , group )
1086
1095
1087
1096
if not secret :
1088
- logging .error ("Can't update secret for relation %s" , str (relation .id ))
1097
+ logging .error ("Can't delete secret for relation %s" , str (relation .id ))
1089
1098
return False
1090
1099
1091
1100
old_content = secret .get_content ()
@@ -1827,7 +1836,8 @@ def _assign_relation_alias(self, relation_id: int) -> None:
1827
1836
1828
1837
# We need to set relation alias also on the application level so,
1829
1838
# it will be accessible in show-unit juju command, executed for a consumer application unit
1830
- self .update_relation_data (relation_id , {"alias" : available_aliases [0 ]})
1839
+ if self .local_unit .is_leader ():
1840
+ self .update_relation_data (relation_id , {"alias" : available_aliases [0 ]})
1831
1841
1832
1842
def _emit_aliased_event (self , event : RelationChangedEvent , event_name : str ) -> None :
1833
1843
"""Emit an aliased event to a particular relation if it has an alias.
@@ -1914,6 +1924,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
1914
1924
1915
1925
# Sets both database and extra user roles in the relation
1916
1926
# if the roles are provided. Otherwise, sets only the database.
1927
+ if not self .local_unit .is_leader ():
1928
+ return
1929
+
1917
1930
if self .extra_user_roles :
1918
1931
self .update_relation_data (
1919
1932
event .relation .id ,
@@ -2173,6 +2186,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
2173
2186
"""Event emitted when the Kafka relation is created."""
2174
2187
super ()._on_relation_created_event (event )
2175
2188
2189
+ if not self .local_unit .is_leader ():
2190
+ return
2191
+
2176
2192
# Sets topic, extra user roles, and "consumer-group-prefix" in the relation
2177
2193
relation_data = {
2178
2194
f : getattr (self , f .replace ("-" , "_" ), "" )
@@ -2345,6 +2361,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
2345
2361
"""Event emitted when the OpenSearch relation is created."""
2346
2362
super ()._on_relation_created_event (event )
2347
2363
2364
+ if not self .local_unit .is_leader ():
2365
+ return
2366
+
2348
2367
# Sets both index and extra user roles in the relation if the roles are provided.
2349
2368
# Otherwise, sets only the index.
2350
2369
data = {"index" : self .index }
0 commit comments