operator: Should relation data be visible to charm code from within a `relation-broken` hook?
Currently, harness first emits relation-broken and only then invalidates the data.
This means that relation data is still accessible by charm code while inside the relation-broken hook. Is that intentional?
Based on the event page it sounds like charm code shouldn’t be able to see any data when inside the broken hook.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 20 (12 by maintainers)
FYI in some cases (but not all) accessing the remote application data in a relation broken event causes an error
See: https://bugs.launchpad.net/juju/+bug/1960934 https://github.com/canonical/operator/blob/734e12dcfde93d7081aed5573e011128d98fd84a/ops/model.py#L1341-L1349 https://github.com/canonical/mysql-router-k8s-operator/issues/73
@PietroPasotti just gave me an idea: If we always defer a relation-broken event, then next hook (on update-status the latest) there will be no data left in relation data, so charm code could operate on the entire relation data, i.e. without needing to work with the delta that a relation-broken implies.
This is not a great pattern, but it conveys well our dissonance about relation-broken.