fix change_optional bug when no root set yet + small add_eid_restriction improvement stable
authorFlorent Cayré <florent.cayre@gmail.com>
Thu, 26 May 2011 01:50:01 +0200
branchstable
changeset 631 6b28ea39cf54
parent 615 7d368dd97930
child 632 7108e8bc1696
child 636 6030a30b10af
fix change_optional bug when no root set yet + small add_eid_restriction improvement
nodes.py
--- a/nodes.py	Thu Feb 03 19:36:52 2011 +0100
+++ b/nodes.py	Thu May 26 01:50:01 2011 +0200
@@ -184,9 +184,10 @@
         return self.add_restriction(make_relation(lhsvar, rtype, (rhsvar,),
                                                   VariableRef))
 
-    def add_eid_restriction(self, var, eid):
+    def add_eid_restriction(self, var, eid, c_type='Int'):
         """builds a restriction node to express '<var> eid <eid>'"""
-        return self.add_constant_restriction(var, 'eid', eid, 'Int')
+        assert c_type in ('Int', 'Substitute'), "Error got c_type=%r in eid restriction" % c_type
+        return self.add_constant_restriction(var, 'eid', eid, c_type)
 
     def add_type_restriction(self, var, etype):
         """builds a restriction node to express : variable is etype"""
@@ -478,7 +479,7 @@
 
     def change_optional(self, value):
         root = self.root
-        if root.should_register_op and value != self.optional:
+        if root is not None and root.should_register_op and value != self.optional:
             from rql.undo import SetOptionalOperation
             root.undo_manager.add_operation(SetOptionalOperation(self, self.optional))
         self.optional= value