<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def attach_session(self):
 """ Create a session and inject it as context for this command and any subcommands. """

        assert self.session is None
        root = self.find_root()
        session = self.Session(root)
        root.inject_context(session=session)
        return session