Skip to content

Commit

Permalink
Merge branch 'main' into add-storage-clearer-use-1127
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer authored Mar 18, 2024
2 parents 8ba6878 + 82cadf2 commit c83d77f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ class Relation:
id: int
"""The identifier for a particular relation."""

app: Optional[Application]
app: Application
"""Represents the remote application of this relation.
For peer relations, this will be the local application.
Expand Down Expand Up @@ -1478,32 +1478,32 @@ def __init__(
backend: '_ModelBackend', cache: '_ModelCache', active: bool = True):
self.name = relation_name
self.id = relation_id
self.app: Optional[Application] = None
self.units: Set[Unit] = set()
self.active = active

if is_peer:
# For peer relations, both the remote and the local app are the same.
self.app = our_unit.app
# For peer relations, both the remote and the local app are the same.
app = our_unit.app if is_peer else None

try:
for unit_name in backend.relation_list(self.id):
unit = cache.get(Unit, unit_name)
self.units.add(unit)
if self.app is None:
if app is None:
# Use the app of one of the units if available.
self.app = unit.app
app = unit.app
except RelationNotFoundError:
# If the relation is dead, just treat it as if it has no remote units.
self.active = False

# If we didn't get the remote app via our_unit.app or the units list,
# look it up via JUJU_REMOTE_APP or "relation-list --app".
if self.app is None:
if app is None:
app_name = backend.relation_remote_app_name(relation_id)
if app_name is not None:
self.app = cache.get(Application, app_name)
app = cache.get(Application, app_name)

# self.app will not be None and always be set because of the fallback mechanism above.
self.app = typing.cast(Application, app)
self.data = RelationData(self, our_unit, backend)

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ def add_relation_unit(self, relation_id: int, remote_unit_name: str) -> None:
'but no relation matching that name was found.')

self._backend._relation_data_raw[relation_id][remote_unit_name] = {}
app = cast(model.Application, relation.app) # should not be None since we're testing
app = relation.app
if not remote_unit_name.startswith(app.name):
warnings.warn(
'Remote unit name invalid: the remote application of {} is called {!r}; '
Expand Down

0 comments on commit c83d77f

Please sign in to comment.