canonical / operator

Pure Python framework for writing Juju charms
Apache License 2.0
247 stars 119 forks source link

fix: remote unit data is available in relation-departed #1364

Open tonyandrewmeyer opened 2 months ago

tonyandrewmeyer commented 2 months ago

During relation-departed and relation-broken, the remote unit data should still be available to the charm, but the relation is no longer included in relation-list, so it's not available by the usual means (but is available when using the hook tool directly).

When a remote unit name is provided in the Juju context, ensure that unit is included in the relation units.

Fixes #1109

tonyandrewmeyer commented 2 months ago

This can be done much more simply by adding this at line 208 of _main.py:

        if relation:
            relation.data._data[kwargs['unit']] = ops.model.RelationDataContent(
                relation, kwargs['unit'], model._backend
            )

Pros/cons compared to the current state of the branch (I've manually tested that both work, but unit tests are non-trivial so want to finalise on an approach before committing to those):

The more I work on this, the more it feels like we're working around Juju behaviour and perhaps we should be advocating for a change in Juju instead (to only change relation-list at the conclusion of relation-broken).

dimaqq commented 1 month ago

@tonyandrewmeyer still draft or ready for review and possibly merge?

tonyandrewmeyer commented 1 month ago

@tonyandrewmeyer still draft or ready for review and possibly merge?

Still draft, expecting to get back to this in the next few days.