diff --git a/test/unittest_editextensions.py b/test/unittest_editextensions.py
index e7e1fc35bad52024730b72aaa382f6083f8cf3d2_dGVzdC91bml0dGVzdF9lZGl0ZXh0ZW5zaW9ucy5weQ==..e54b9379fc7cbb418c1989c53b2c932eed398df5_dGVzdC91bml0dGVzdF9lZGl0ZXh0ZW5zaW9ucy5weQ== 100644
--- a/test/unittest_editextensions.py
+++ b/test/unittest_editextensions.py
@@ -1,4 +1,4 @@
-# copyright 2004-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of rql.
@@ -19,6 +19,7 @@
 from logilab.common.testlib import TestCase, unittest_main
 
 from rql import parse
+from rql.nodes import Exists
 from rql.editextensions import *
 
 class RQLUndoTestCase(TestCase):
@@ -22,7 +23,7 @@
 from rql.editextensions import *
 
 class RQLUndoTestCase(TestCase):
-    
+
     def test_selected(self):
         rqlst = parse('Person X')
         orig = rqlst.as_string()
@@ -40,7 +41,7 @@
         self.assertEqual(rqlst.as_string(), orig)
         # check references after recovering
         rqlst.check_references()
-    
+
     def test_selected3(self):
         rqlst = parse('Any lower(N) WHERE X is Person, X name N')
         orig = rqlst.as_string()
@@ -58,7 +59,7 @@
         self.assertEqual(rqlst.as_string(), orig)
         # check references after recovering
         rqlst.check_references()
-        
+
     def test_undefine_1(self):
         rqlst = parse('Person X, Y WHERE X travaille_pour Y')
         orig = rqlst.as_string()
@@ -73,7 +74,7 @@
         self.assertEqual(rqlst.as_string(), orig)
         # check references after recovering
         rqlst.check_references()
-        
+
     def test_undefine_2(self):
         rqlst = parse('Person X')
         orig = rqlst.as_string()
@@ -90,7 +91,24 @@
         self.assertEqual(rqlst.as_string(), orig)
         # check references after recovering
         rqlst.check_references()
-        
-        
+
+
+    def test_remove_exists(self):
+        rqlst = parse('Any U,COUNT(P) GROUPBY U WHERE U is CWUser, P? patch_reviewer U, EXISTS(P in_state S AND S name "pouet")').children[0]
+        orig = rqlst.as_string()
+        rqlst.save_state()
+        n = [r for r in rqlst.get_nodes(Exists)][0].query
+        rqlst.remove_node(n)
+        # check operations
+        self.assertEqual(rqlst.as_string(), 'Any U,COUNT(P) GROUPBY U WHERE U is CWUser, P? patch_reviewer U')
+        # check references before recovering
+        rqlst.check_references()
+        rqlst.recover()
+        # check equivalence
+        self.assertEqual(rqlst.as_string(), orig)
+        # check references after recovering
+        rqlst.check_references()
+
+
 if __name__ == '__main__':
     unittest_main()
diff --git a/undo.py b/undo.py
index e7e1fc35bad52024730b72aaa382f6083f8cf3d2_dW5kby5weQ==..e54b9379fc7cbb418c1989c53b2c932eed398df5_dW5kby5weQ== 100644
--- a/undo.py
+++ b/undo.py
@@ -1,4 +1,4 @@
-# copyright 2004-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of rql.
@@ -19,7 +19,7 @@
 
 __docformat__ = "restructuredtext en"
 
-from rql.nodes import VariableRef, Variable, BinaryNode
+from rql.nodes import Exists, VariableRef, Variable, BinaryNode
 from rql.stmts import Select
 
 class SelectionManager(object):
@@ -142,8 +142,8 @@
     def __init__(self, node, parent, stmt, index):
         NodeOperation.__init__(self, node, stmt)
         self.node_parent = parent
-        #if isinstance(parent, Select):
-        #    assert self.node is parent.where
+        if index is None:
+            assert isinstance(parent, (Exists, Select)), (node, parent)
         self.index = index
         # XXX FIXME : find a better way to do that
         self.binary_remove = isinstance(node, BinaryNode)
@@ -152,9 +152,11 @@
         """undo the operation on the selection"""
         parent = self.node_parent
         if self.index is None:
-            assert isinstance(parent, Select)
-            sibling = parent.where = self.node
-            parent.where = self.node
+            if isinstance(parent, Select):
+                parent.where = self.node
+            else: # Exists
+                parent.query = self.node
+            sibling = self.node
         if self.binary_remove:
             # if 'parent' was a BinaryNode, then first reinsert the removed node
             # at the same pos in the original 'parent' Binary Node, and then