WorkspaceBuilder._session not initialized to None in __init__
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start in src/tmuxp/workspace/builder.py, especially init, the _session declaration, and the session property around the cited lines. Trace the fresh-session and ObjectDoesNotExist paths, then verify that accessing session before build produces the intended SessionMissingWorkspaceException and that the TODO is resolved.
Written by the indexing model from the issue text.
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:
pass
If 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._session
Accessing 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
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 248
- Avg merge
- 2h 13m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tmux-python/tmuxp
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tmux-python/tmuxp#939 · 1 comment ·
-
enhancement WorkspaceBuilder
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tmux-python/tmuxp#1062 ·
-
enhancement need-comments WorkspaceBuilder
Difficulty 5/5 Over a week Newbie friendliness 35/100
tmux-python/tmuxp#1058 · 2 comments ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
tmux-python/tmuxp#1053 · 10 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
tmux-python/tmuxp#1051 ·
All issues in tmux-python/tmuxp
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100