Skip to content

Commit d4fb61b

Browse files
Merge pull request #100 from canonical/older-ops-compat
Older ops compat
2 parents 9592497 + 1ca86a5 commit d4fb61b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

scenario/ops_main_mock.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,27 @@ def setup_framework(
110110

111111
meta = CharmMeta.from_yaml(metadata, actions_metadata)
112112

113-
# If we are in a RelationBroken event, we want to know which relation is
114-
# broken within the model, not only in the event's `.relation` attribute.
115-
broken_relation_id = (
116-
event.relation.relation_id if event.name.endswith("_relation_broken") else None # type: ignore
117-
)
118-
model = ops.model.Model(meta, model_backend, broken_relation_id=broken_relation_id)
113+
# ops >= 2.10
114+
if inspect.signature(ops.model.Model).parameters.get("broken_relation_id"):
115+
# If we are in a RelationBroken event, we want to know which relation is
116+
# broken within the model, not only in the event's `.relation` attribute.
117+
broken_relation_id = (
118+
event.relation.relation_id # type: ignore
119+
if event.name.endswith("_relation_broken")
120+
else None
121+
)
122+
123+
model = ops.model.Model(
124+
meta,
125+
model_backend,
126+
broken_relation_id=broken_relation_id,
127+
)
128+
else:
129+
ops_logger.warning(
130+
"It looks like this charm is using an older `ops` version. "
131+
"You may experience weirdness. Please update ops.",
132+
)
133+
model = ops.model.Model(meta, model_backend)
119134

120135
charm_state_path = charm_dir / CHARM_STATE_FILE
121136

0 commit comments

Comments
 (0)