{"record":{"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":"exception","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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/nodes.py#L206-L242","documentation":"Raised by Node.from_parent when 'session' appears in the kwargs. Like config, session is inherited from the parent and must not be passed explicitly (lines 223-224). The guard prevents inconsistent session assignment and fails fast before construction proceeds.","triggerScenarios":"Node.from_parent(parent, session=sess, ...); passing session= as a kwarg to a subclass from_parent; refactoring constructor calls without removing session.","commonSituations":"Plugin authors copying all Node.__init__ kwargs into from_parent; legacy code that constructed nodes with explicit sessions.","solutions":["Drop session= from the from_parent call; it is derived from the parent.","Ensure the parent node belongs to the intended session.","Review from_parent call sites for stray session kwargs."],"exampleFix":"// before\nitem = MyItem.from_parent(parent=collector, name='x', session=session)\n// after\nitem = MyItem.from_parent(parent=collector, name='x')","handlingStrategy":"type-guard","validationCode":"kw.pop('session', None)  # never pass session to from_parent","typeGuard":"def _from_parent_kw_clean(kw) -> bool:\n    return 'session' not in kw and 'config' not in kw","tryCatchPattern":null,"preventionTips":["Remove session/config from kwargs before from_parent.","Rely on the parent to propagate session."],"tags":["pytest","nodes","typeerror","internal-api"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}