{"record":{"id":"b1dfc269e0c47c43","repo":"Textualize/textual","slug":"no-tab-with-id-active-r","errorCode":null,"errorMessage":"No Tab with id {active!r}","messagePattern":"No Tab with id (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_tabs.py","lineNumber":580,"sourceCode":"        else:\n            next_tab = None\n\n        async def do_remove() -> None:\n            \"\"\"Perform the remove after refresh so the underline bar gets new positions.\"\"\"\n            await remove_tab.remove()\n            if not self.query(\"#tabs-list > Tab\"):\n                self.active = \"\"\n            elif next_tab is not None:\n                self.active = next_tab.id or \"\"\n            else:\n                self._highlight_active(animate=False)\n\n        return AwaitComplete(do_remove())\n\n    def validate_active(self, active: str) -> str:\n        \"\"\"Check id assigned to active attribute is a valid tab.\"\"\"\n        if active and not self.query(f\"#tabs-list > #{active}\"):\n            raise ValueError(f\"No Tab with id {active!r}\")\n        return active\n\n    @property\n    def active_tab(self) -> Tab | None:\n        \"\"\"The currently active tab, or None if there are no active tabs.\"\"\"\n        try:\n            return self.query_one(\"#tabs-list Tab.-active\", Tab)\n        except NoMatches:\n            return None\n\n    def _on_mount(self, _: Mount) -> None:\n        \"\"\"Make the first tab active.\"\"\"\n        if self._first_active is not None:\n            self.active = self._first_active\n        if not self.active:\n            try:\n                tab = self.query(\"#tabs-list > Tab\").first(Tab)\n            except NoMatches:","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_tabs.py#L562-L598","documentation":"Raised by Tabs.validate_active when the active reactive is set to a non-empty id that does not match any Tab in the tabs-list. The validator queries `#tabs-list > #{active}` and rejects unknown ids immediately.","triggerScenarios":"Tabs(active='missing-id') when no Tab with that id was added; tabs.active = 'foo' before the Tab('...', id='foo') is added; or after removing the active tab and setting a stale id.","commonSituations":"Restoring a persisted active tab id after the tab set changed, ordering issues where active is set before children are added, typos in ids.","solutions":["Ensure the Tab with that id exists (added as a child) before setting active.","Use the tab's id exactly (ids are case-sensitive and become CSS ids).","When restoring state, verify the id still exists or fall back to the first tab."],"exampleFix":"# before\ntabs = Tabs(active='settings')\ntabs.add_tab(Tab('Settings', id='settings'))  # too late? ensure order/await\n# after\ntabs = Tabs(Tab('Settings', id='settings'), active='settings')","handlingStrategy":"try-catch","validationCode":"if not tabs.query(f'#tabs-list > #{tab_id}'):\n    tab_id = ''  # or first tab id","typeGuard":null,"tryCatchPattern":"try:\n    tabs.active = saved_id\nexcept ValueError:\n    tabs.active = ''","preventionTips":["Add Tabs children before setting active","Verify persisted tab ids still exist before restoring"],"tags":["tabs","active-id","validation","textual"],"backgroundTag":"id-not-found","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}