# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1270641089 -7200
#      Wed Apr 07 13:51:29 2010 +0200
# Node ID 60255eecf96cb50faad89082414f17b4b4323ad5
# Parent  7f40b201b020d9e294ea744669de2391b5f88ee1
cleanup rql simplification code

diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -136,11 +136,8 @@
                 var = uidrel.children[0].variable
                 vconsts = []
                 rhs = uidrel.children[1].children[0]
-                #from rql.nodes import Constant
-                #assert isinstance(rhs, nodes.Constant), rhs
                 for vref in var.references():
                     rel = vref.relation()
-                    #assert vref.parent
                     if rel is None:
                         term = vref
                         while not term.parent is select:
@@ -162,9 +159,6 @@
                             rhs = copy_uid_node(select, rhs, vconsts)
                             select.groupby[select.groupby.index(vref)] = rhs
                             rhs.parent = select
-                    elif rel is uidrel:
-                        # drop this relation
-                        rel.parent.remove(rel)
                     elif rel.is_types_restriction():
                         stinfo['typerel'] = None
                         rel.parent.remove(rel)
@@ -172,6 +166,7 @@
                         rhs = copy_uid_node(select, rhs, vconsts)
                         vref.parent.replace(vref, rhs)
                 del select.defined_vars[var.name]
+                uidrel.parent.remove(uidrel)
                 stinfo['uidrel'] = None
                 rewritten = True
                 if vconsts: