diff --git a/flask_potion/contrib/alchemy/manager.py b/flask_potion/contrib/alchemy/manager.py index 6aaaa40..f80abfb 100644 --- a/flask_potion/contrib/alchemy/manager.py +++ b/flask_potion/contrib/alchemy/manager.py @@ -328,10 +328,18 @@ def relation_add(self, item, attribute, target_resource, target_item): def relation_remove(self, item, attribute, target_resource, target_item): before_remove_from_relation.send(self.resource, item=item, attribute=attribute, child=target_item) try: - getattr(item, attribute).remove(target_item) - after_remove_from_relation.send(self.resource, item=item, attribute=attribute, child=target_item) + collection = getattr(item, attribute) except ValueError: pass # if the relation does not exist, do nothing + else: + if target_item in collection: + collection.remove(target_item) + after_remove_from_relation.send( + self.resource, + item=item, + attribute=attribute, + child=target_item, + ) def commit(self): session = self._get_session()