{"record":{"id":"d80926df67e94f0a","repo":"slint-ui/slint","slug":"type-self-name-does-not-support-inserting-rows","errorCode":null,"errorMessage":"{type(self).__name__} does not support inserting rows","messagePattern":"(.+?) does not support inserting rows","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"api/python/slint/slint/models.py","lineNumber":78,"sourceCode":"        \"\"\"Add a new row to the model with the provided value.\n        The default implementation calls `insert_row` with the row count.\"\"\"\n        self.insert_row(self.row_count(), value)\n\n    def remove_row(self, row: int) -> None:\n        \"\"\"Remove the row at the given index.\n        Raises an exception when the model rejects the modification.\n        The default implementation raises NotImplementedError. A model that\n        supports removing rows should also call `notify_row_removed`.\"\"\"\n        raise NotImplementedError(\n            f\"{type(self).__name__} does not support removing rows\"\n        )\n\n    def insert_row(self, row: int, value: T) -> None:\n        \"\"\"Insert a new row at the given index.\n        Raises an exception when the model rejects the modification.\n        The default implementation raises NotImplementedError. A model that\n        supports inserting rows should also call `notify_row_added`.\"\"\"\n        raise NotImplementedError(\n            f\"{type(self).__name__} does not support inserting rows\"\n        )\n\n    def notify_row_changed(self, row: int) -> None:\n        \"\"\"Call this method from a sub-class to notify the views that a row has changed.\"\"\"\n        super().notify_row_changed(row)\n\n    def notify_row_removed(self, row: int, count: int) -> None:\n        \"\"\"Call this method from a sub-class to notify the views that\n        `count` rows have been removed starting at `row`.\"\"\"\n        super().notify_row_removed(row, count)\n\n    def notify_row_added(self, row: int, count: int) -> None:\n        \"\"\"Call this method from a sub-class to notify the views that\n        `count` rows have been added starting at `row`.\"\"\"\n        super().notify_row_added(row, count)\n\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/api/python/slint/slint/models.py#L60-L96","documentation":"The base Model class's insert_row default implementation raises NotImplementedError because a generic model cannot insert rows. Subclasses must override insert_row (and call notify_row_added) to support insertion.","triggerScenarios":"Calling model.insert_row(index, value) on a model whose class does not override insert_row.","commonSituations":"Subclassing slint.Model for a read-only data source and later appending items from UI logic; passing a custom minimal model to a component that adds rows.","solutions":["Use slint.ListModel, which implements insert_row/append.","In a custom model subclass, override insert_row to insert into the backing store and call self.notify_row_added(row, 1).","If the model is intentionally immutable, avoid calling insert_row and expose updates via property bindings instead."],"exampleFix":"# before\nclass MyModel(slint.Model):\n    def row_count(self): return len(self.data)\n\n# after\nclass MyModel(slint.Model):\n    def row_count(self): return len(self.data)\n    def insert_row(self, row, value):\n        self.data.insert(row, value)\n        self.notify_row_added(row, 1)","handlingStrategy":"type-guard","validationCode":"def supports_insert(model):\n    return type(model).insert_row is not slint.Model.insert_row","typeGuard":"def supports_insert(model):\n    return isinstance(model, slint.ListModel) or overrides(model, \"insert_row\")","tryCatchPattern":"try:\n    model.insert_row(0, item)\nexcept NotImplementedError:\n    model = slint.ListModel([item] + existing)","preventionTips":["Use slint.ListModel when rows will be added at runtime.","Override insert_row + notify_row_added in custom mutable models."],"tags":["python","model","not-implemented","unsupported-operation"],"backgroundTag":"method-not-implemented","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}