{"id":"c04645118cb1695c","repo":"pytest-dev/pytest","slug":"session-is-not-a-valid-argument-for-from-parent","errorCode":null,"errorMessage":"session is not a valid argument for from_parent","messagePattern":"session is not a valid argument for from_parent","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/nodes.py","lineNumber":224,"sourceCode":"        # Deprecated alias. Was never public. Can be removed in a few releases.\n        self._store = self.stash\n\n    @classmethod\n    def from_parent(cls, parent: Node, **kw) -> Self:\n        \"\"\"Public constructor for Nodes.\n\n        This indirection got introduced in order to enable removing\n        the fragile logic from the node constructors.\n\n        Subclasses can use ``super().from_parent(...)`` when overriding the\n        construction.\n\n        :param parent: The parent node of this Node.\n        \"\"\"\n        if \"config\" in kw:\n            raise TypeError(\"config is not a valid argument for from_parent\")\n        if \"session\" in kw:\n            raise TypeError(\"session is not a valid argument for from_parent\")\n        return cls._create(parent=parent, **kw)\n\n    @property\n    def ihook(self) -> pluggy.HookRelay:\n        \"\"\"Path-sensitive hook proxy used to call pytest hooks.\"\"\"\n        return self.session.gethookproxy(self.path)\n\n    def __repr__(self) -> str:\n        return \"<{} {}>\".format(self.__class__.__name__, getattr(self, \"name\", None))\n\n    def warn(self, warning: Warning) -> None:\n        \"\"\"Issue a warning for this Node.\n\n        Warnings will be displayed after the test session, unless explicitly suppressed.\n\n        :param Warning warning:\n            The warning instance to issue.\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/nodes.py#L206-L242","documentation":"Node.from_parent intentionally rejects a `session` keyword. session is inherited from the parent (parent.session) inside from_parent, so an explicit one would be contradictory and is rejected with TypeError.","triggerScenarios":"Calling MyNode.from_parent(parent, session=s, ...) or forwarding session through **kw. Usually leftover from a pre-from_parent constructor pattern.","commonSituations":"Plugins ported from older APIs that accepted session; overriding from_parent and forwarding **kwargs blindly.","solutions":["Drop the session kwarg from the from_parent call","If a distinct session is genuinely required, bypass from_parent and use the constructor directly"],"exampleFix":"// before\nitem = MyItem.from_parent(parent, name=n, session=s)\n// after\nitem = MyItem.from_parent(parent, name=n)","handlingStrategy":"validation","validationCode":"def safe_from_parent(cls, parent, **kw):\n    kw.pop('session', None)  # never forward session\n    return cls.from_parent(parent, **kw)","typeGuard":"def kwargs_have_no_session(kw) -> bool:\n    return 'session' not in kw","tryCatchPattern":null,"preventionTips":["Never forward session through from_parent; it is inherited","Audit from_parent overrides for stray **kwargs leaking session"],"tags":["nodes","plugin-api","pytest","from-parent"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}