{"record":{"id":"62a670f2f83f38c4","repo":"sqlalchemy/sqlalchemy","slug":"value-not-in-list","errorCode":null,"errorMessage":"value not in list","messagePattern":"value not in list","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/sqlalchemy/ext/associationproxy.py","lineNumber":1588,"sourceCode":"                count += 1\n        return count\n\n    def extend(self, values: Iterable[_T]) -> None:\n        for v in values:\n            self.append(v)\n\n    def insert(self, index: int, value: _T) -> None:\n        self.col[index:index] = [self._create(value)]\n\n    def pop(self, index: int = -1) -> _T:\n        return self.getter(self.col.pop(index))\n\n    def remove(self, value: _T) -> None:\n        for i, val in enumerate(self):\n            if val == value:\n                del self.col[i]\n                return\n        raise ValueError(\"value not in list\")\n\n    def reverse(self) -> NoReturn:\n        \"\"\"Not supported, use reversed(mylist)\"\"\"\n\n        raise NotImplementedError()\n\n    def sort(self) -> NoReturn:\n        \"\"\"Not supported, use sorted(mylist)\"\"\"\n\n        raise NotImplementedError()\n\n    def clear(self) -> None:\n        del self.col[0 : len(self.col)]\n\n    def __eq__(self, other: object) -> bool:\n        return list(self) == other\n\n    def __ne__(self, other: object) -> bool:","sourceCodeStart":1570,"sourceCodeEnd":1606,"githubUrl":"https://github.com/sqlalchemy/sqlalchemy/blob/5995834ee06fc5cae45f86992d778fd5357c08ee/lib/sqlalchemy/ext/associationproxy.py#L1570-L1606","documentation":"Raised by _AssociationList.remove when the value is not present in the proxied list, exactly like Python's built-in list.remove which raises ValueError. The proxy iterates its members, compares via the getter, and if no match is found raises ValueError(\"value not in list\").","triggerScenarios":"user.keywords.remove(some_keyword) where some_keyword is not currently in the collection; calling remove twice; removing a value that was never appended.","commonSituations":"Idempotent cleanup code that removes an item without checking membership first; UI-driven remove operations; concurrent edits that already removed the value.","solutions":["Guard with membership: if value in user.keywords: user.keywords.remove(value).","Catch ValueError and treat removal as already-done (idempotent).","Prefer a helper that discards if present."],"exampleFix":"# before\nuser.keywords.remove(kw)  # raises if absent\n# after\ntry:\n    user.keywords.remove(kw)\nexcept ValueError:\n    pass  # already absent","handlingStrategy":"try-catch","validationCode":"if value in user.keywords:\n    user.keywords.remove(value)","typeGuard":null,"tryCatchPattern":"try:\n    user.keywords.remove(value)\nexcept ValueError:\n    pass  # already absent; idempotent","preventionTips":["Check membership before calling remove on proxied lists.","Wrap removes in try/except ValueError for idempotent cleanup.","Drive removals from UI/queue logic that already verified presence."],"tags":["orm","association-proxy","collections","error-handling"],"backgroundTag":null,"analyzedSha":"5995834ee06fc5cae45f86992d778fd5357c08ee","analyzedAt":"2026-08-07T20:40:23.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}