Closed dimaqq closed 2 months ago
An endpoint name does not uniquely identify a relation. If you want to get the relations for a given endpoint, use get_relations
. If you know there will only be one, you can make use of that knowledge when handling the response.
A charm can't add or remove relations, so the relation will exist in the input state. The expected pattern is:
rel = Relation(...)
state_in = State(relations={rel})
state_out = ctx.run(..., state_in)
assert state_out.get_relation(rel.id)...
Today I have 2 options:
.get_relation(0)
Given that first argument, the relation endpoint is allowed to be positional, consider expanding
state.get_relation
to allow a string argument, which would mean the endpoint name. The code would then, perhaps, ensure that there's only one relation like this.