@@ -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 = 40
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
##############################################################################
@@ -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
+ DATABASE_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 .DATABASE_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
@@ -3290,6 +3305,8 @@ class KafkaRequiresEvents(CharmEvents):
3290
3305
class KafkaProviderData (ProviderData ):
3291
3306
"""Provider-side of the Kafka relation."""
3292
3307
3308
+ DATABASE_FIELD = "topic"
3309
+
3293
3310
def __init__ (self , model : Model , relation_name : str ) -> None :
3294
3311
super ().__init__ (model , relation_name )
3295
3312
@@ -3539,6 +3556,8 @@ class OpenSearchRequiresEvents(CharmEvents):
3539
3556
class OpenSearchProvidesData (ProviderData ):
3540
3557
"""Provider-side of the OpenSearch relation."""
3541
3558
3559
+ DATABASE_FIELD = "index"
3560
+
3542
3561
def __init__ (self , model : Model , relation_name : str ) -> None :
3543
3562
super ().__init__ (model , relation_name )
3544
3563
0 commit comments