-
Notifications
You must be signed in to change notification settings - Fork 236
Description
Bug
WorkspaceBuilder._session is declared as a class-level type annotation (_session: Session | None at line 308 of src/tmuxp/workspace/builder.py) but is never initialized to None in __init__.
Problem
The attribute is only assigned conditionally inside __init__ (lines 377-387):
if self.server is not None and self.session_exists(
session_name=self.session_config["session_name"],
):
try:
session = self.server.sessions.get(
session_name=self.session_config["session_name"],
)
assert session is not None
self._session = session
except ObjectDoesNotExist:
passIf the session doesn't already exist (the normal case for a fresh tmuxp load), or if ObjectDoesNotExist is raised, _session is never set.
The session property (lines 389-394) expects _session to exist:
@property
def session(self) -> Session:
if self._session is None:
raise exc.SessionMissingWorkspaceException
return self._sessionAccessing self._session when it was never assigned raises AttributeError, not the intended SessionMissingWorkspaceException.
Why it hasn't crashed in practice
build() always assigns self._session before the property is accessed. But if any code path accesses self.session before build() completes, it gets AttributeError instead of the semantically correct exception.
Fix
Add self._session = None early in __init__, before the conditional block. Also resolve the existing TODO at lines 357-358:
TODO: Initialize :class:`libtmux.Session` from here, in ``self.session``.
Files
src/tmuxp/workspace/builder.pylines 308, 360-387, 389-394