@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331
331
332
332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333
333
# to 0 if you are raising the major API version
334
- LIBPATCH = 39
334
+ LIBPATCH = 41
335
335
336
336
PYDEPS = ["ops>=2.0.0" ]
337
337
@@ -391,6 +391,10 @@ class IllegalOperationError(DataInterfacesError):
391
391
"""To be used when an operation is not allowed to be performed."""
392
392
393
393
394
+ class PrematureDataAccessError (DataInterfacesError ):
395
+ """To be raised when the Relation Data may be accessed (written) before protocol init complete."""
396
+
397
+
394
398
##############################################################################
395
399
# Global helpers / utilities
396
400
##############################################################################
@@ -605,7 +609,7 @@ def get_group(self, group: str) -> Optional[SecretGroup]:
605
609
class CachedSecret :
606
610
"""Locally cache a secret.
607
611
608
- The data structure is precisely re-using /simulating as in the actual Secret Storage
612
+ The data structure is precisely reusing /simulating as in the actual Secret Storage
609
613
"""
610
614
611
615
KNOWN_MODEL_ERRORS = [MODEL_ERRORS ["no_label_and_uri" ], MODEL_ERRORS ["owner_no_refresh" ]]
@@ -1453,6 +1457,8 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
1453
1457
class ProviderData (Data ):
1454
1458
"""Base provides-side of the data products relation."""
1455
1459
1460
+ RESOURCE_FIELD = "database"
1461
+
1456
1462
def __init__ (
1457
1463
self ,
1458
1464
model : Model ,
@@ -1618,6 +1624,15 @@ def _fetch_my_specific_relation_data(
1618
1624
def _update_relation_data (self , relation : Relation , data : Dict [str , str ]) -> None :
1619
1625
"""Set values for fields not caring whether it's a secret or not."""
1620
1626
req_secret_fields = []
1627
+
1628
+ keys = set (data .keys ())
1629
+ if self .fetch_relation_field (relation .id , self .RESOURCE_FIELD ) is None and (
1630
+ keys - {"endpoints" , "read-only-endpoints" , "replset" }
1631
+ ):
1632
+ raise PrematureDataAccessError (
1633
+ "Premature access to relation data, update is forbidden before the connection is initialized."
1634
+ )
1635
+
1621
1636
if relation .app :
1622
1637
req_secret_fields = get_encoded_list (relation , relation .app , REQ_SECRET_FIELDS )
1623
1638
@@ -2348,7 +2363,6 @@ def _update_relation_data(self, relation: Relation, data: Dict[str, str]) -> Non
2348
2363
def _delete_relation_data (self , relation : Relation , fields : List [str ]) -> None :
2349
2364
"""Delete data available (directily or indirectly -- i.e. secrets) from the relation for owner/this_app."""
2350
2365
if self .secret_fields and self .deleted_label :
2351
-
2352
2366
_ , normal_fields = self ._process_secret_fields (
2353
2367
relation ,
2354
2368
self .secret_fields ,
@@ -3290,6 +3304,8 @@ class KafkaRequiresEvents(CharmEvents):
3290
3304
class KafkaProviderData (ProviderData ):
3291
3305
"""Provider-side of the Kafka relation."""
3292
3306
3307
+ RESOURCE_FIELD = "topic"
3308
+
3293
3309
def __init__ (self , model : Model , relation_name : str ) -> None :
3294
3310
super ().__init__ (model , relation_name )
3295
3311
@@ -3539,6 +3555,8 @@ class OpenSearchRequiresEvents(CharmEvents):
3539
3555
class OpenSearchProvidesData (ProviderData ):
3540
3556
"""Provider-side of the OpenSearch relation."""
3541
3557
3558
+ RESOURCE_FIELD = "index"
3559
+
3542
3560
def __init__ (self , model : Model , relation_name : str ) -> None :
3543
3561
super ().__init__ (model , relation_name )
3544
3562
0 commit comments