Skip to content

Commit bc881e4

Browse files
committed
chore: guard access to model.info on connection
1 parent af5fb47 commit bc881e4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

juju/model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import websockets
2525
import yaml
26+
from typing_extensions import deprecated
2627

2728
from . import jasyncio, provisioner, tag, utils
2829
from .annotationhelper import _get_annotations, _set_annotations
@@ -801,13 +802,14 @@ async def connect_current(self):
801802
"""
802803
return await self.connect()
803804

805+
@deprecated("Model.connect_to() is deprecated and will be removed soon")
804806
async def connect_to(self, connection):
805807
conn_params = connection.connect_params()
806808
await self._connect_direct(**conn_params)
807809

808810
async def _connect_direct(self, **kwargs):
809-
if self.info:
810-
uuid = self.info.uuid
811+
if self._info:
812+
uuid = self._info.uuid
811813
elif "uuid" in kwargs:
812814
uuid = kwargs["uuid"]
813815
else:
@@ -1227,6 +1229,9 @@ def info(self) -> ModelInfo:
12271229
12281230
If Model.get_info() has not been called, this will return None.
12291231
"""
1232+
if not self.is_connected():
1233+
raise JujuModelError("Model is not connected")
1234+
12301235
assert self._info is not None
12311236
return self._info
12321237

0 commit comments

Comments
 (0)