{"record":{"id":"dfa5b6253d302865","repo":"Textualize/textual","slug":"no-nodes-match-self-r-on-self-node-r","errorCode":null,"errorMessage":"No nodes match {self!r} on {self.node!r}","messagePattern":"No nodes match (.+?) on (.+?)","errorType":"validation","errorClass":"NoMatches","httpStatus":null,"severity":"error","filePath":"src/textual/css/query.py","lineNumber":249,"sourceCode":"\n        Raises:\n            WrongType: If the wrong type was found.\n            NoMatches: If there are no matching nodes in the query.\n\n        Returns:\n            The matching Widget.\n        \"\"\"\n        _rich_traceback_omit = True\n        if self.nodes:\n            first = self.nodes[0]\n            if expect_type is not None:\n                if not isinstance(first, expect_type):\n                    raise WrongType(\n                        f\"Query value is the wrong type; expected type {expect_type.__name__!r}, found {first}\"\n                    )\n            return first\n        else:\n            raise NoMatches(f\"No nodes match {self!r} on {self.node!r}\")\n\n    if TYPE_CHECKING:\n\n        @overload\n        def only_one(self) -> QueryType: ...\n\n        @overload\n        def only_one(self, expect_type: type[ExpectType]) -> ExpectType: ...\n\n    def only_one(\n        self, expect_type: type[ExpectType] | None = None\n    ) -> QueryType | ExpectType:\n        \"\"\"Get the *only* matching node.\n\n        Args:\n            expect_type: Require matched node is of this type,\n                or None for any type.\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/query.py#L231-L267","documentation":"first() raises NoMatches when the selector matched zero nodes on the queried DOM node. This is the canonical 'selector found nothing' error for query_one/first, including the query and node in the message for debugging.","triggerScenarios":"`self.query_one(\"#submit\")` before the widget is mounted or when the id is misspelled; querying a selector that exists only after compose() completes; querying a removed widget.","commonSituations":"Querying during on_mount before children mount (ordering), wrong/renamed ids, conditional widgets not yet created, or querying the wrong screen/node.","solutions":["Verify the selector matches something in the current DOM (ids spelled the same, widget actually composed)","Move the query to after mounting — e.g. on_mount of the container, or call_before adding with mount and use the returned widget","Use query(...).first() guarded, or catch NoMatches and compose/mount the missing widget on demand"],"exampleFix":"# before\ndef on_mount(self) -> None:\n    self.query_one(\"#late\").focus()  # NoMatches\n# after\ndef on_mount(self) -> None:\n    self.call_after_refresh(self._focus_late)\n\ndef _focus_late(self) -> None:\n    self.query_one(\"#late\").focus()","handlingStrategy":"try-catch","validationCode":"matches = screen.query(selector).nodes\nif matches:\n    node = matches[0]","typeGuard":null,"tryCatchPattern":"from textual.css.query import NoMatches\ntry:\n    w = self.query_one(\"#id\")\nexcept NoMatches:\n    w = None","preventionTips":["Defer queries until after mount (call_after_refresh); double-check ids match compose()"],"tags":["textual","query","no-matches","dom"],"backgroundTag":"element-not-found","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}