{"record":{"id":"1c0b19319119fc51","repo":"Textualize/textual","slug":"no-nodes-match-query-selector-r-on-base-node-r","errorCode":null,"errorMessage":"No nodes match {query_selector!r} on {base_node!r}","messagePattern":"No nodes match (.+?) on (.+?)","errorType":"exception","errorClass":"NoMatches","httpStatus":null,"severity":"error","filePath":"src/textual/dom.py","lineNumber":1505,"sourceCode":"            query_selector = selector.__name__\n\n        if is_id_selector(query_selector):\n            cache_key = (base_node._nodes._updates, query_selector, expect_type)\n            cached_result = base_node._query_one_cache.get(cache_key)\n            if cached_result is not None:\n                return cached_result\n            if (\n                node := walk_breadth_search_id(\n                    base_node, query_selector[1:], with_root=False\n                )\n            ) is not None:\n                if expect_type is not None and not isinstance(node, expect_type):\n                    raise WrongType(\n                        f\"Node matching {query_selector!r} is the wrong type; expected type {expect_type.__name__!r}, found {node}\"\n                    )\n                base_node._query_one_cache[cache_key] = node\n                return node\n            raise NoMatches(f\"No nodes match {query_selector!r} on {base_node!r}\")\n\n        try:\n            selector_set = parse_selectors(query_selector)\n        except TokenError:\n            raise InvalidQueryFormat(\n                f\"Unable to parse {query_selector!r} as a query; check for syntax errors\"\n            ) from None\n\n        if all(selectors.is_simple for selectors in selector_set):\n            cache_key = (base_node._nodes._updates, query_selector, expect_type)\n            cached_result = base_node._query_one_cache.get(cache_key)\n            if cached_result is not None:\n                return cached_result\n        else:\n            cache_key = None\n\n        for node in walk_breadth_first(base_node, with_root=False):\n            if not match(selector_set, node):","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/dom.py#L1487-L1523","documentation":"NoMatches from query_one when an #id (fast-path) lookup found no node with that id anywhere under the base node. The message echoes the selector and base node for debugging.","triggerScenarios":"Calling query_one('#missing') before the widget is mounted/composed; querying on a subtree that doesn't contain the id; typos or ids set after the query runs.","commonSituations":"Querying in on_mount of a parent before children mount; querying the app when the widget lives on a different screen; id set dynamically after query timing (race with worker/compose).","solutions":["Verify the widget exists at query time — move the query to on_mount of the screen/app or after compose completes","Check spelling of the id and that it's set at construction (Widget(id='x'))","Use query_one_optional-style checks or query(...) with a None guard when existence is uncertain"],"exampleFix":"# before\ndef on_mount(self):\n    self.query_one('#input').focus()  # NoMatches: children not mounted yet\n\n# after\nclass MyApp(App):\n    async def on_mount(self):\n        await self.push_screen(MainScreen())\n    \nclass MainScreen(Screen):\n    def on_mount(self):\n        self.query_one('#input').focus()  # after compose, works","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def has_id(base, node_id: str) -> bool:\n    return base.query(f'#{node_id}').first() is not None","tryCatchPattern":"from textual.css.query import NoMatches\ntry:\n    w = self.query_one('#foo')\nexcept NoMatches:\n    w = None\n    # mount it or defer","preventionTips":["Query from screen on_mount, not widget __init__","Verify ids set in compose() match queried ids","Use optional/empty-query patterns when existence is uncertain"],"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"}