summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/sql/util.py3
-rw-r--r--lib/sqlalchemy/topological.py19
3 files changed, 15 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index 39bba20bb..f22905f26 100644
--- a/CHANGES
+++ b/CHANGES
@@ -30,6 +30,10 @@ CHANGES
- Fixed a potential issue in topological cycle detection
introduced in 0.6beta3, for units of work with long
dependency cycles.
+
+ - id(obj) is no longer used internally within topological.py,
+ as the sorting functions now require hashable objects
+ only. [ticket:1756]
- sql
- Restored some bind-labeling logic from 0.5 which ensures
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index d5575e0e7..5a439b099 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -15,7 +15,8 @@ def sort_tables(tables):
parent_table = fkey.column.table
if parent_table in tables:
child_table = fkey.parent.table
- tuples.append( ( parent_table, child_table ) )
+ if parent_table is not child_table:
+ tuples.append((parent_table, child_table))
for table in tables:
visitors.traverse(table, {'schema_visitor':True}, {'foreign_key':visit_foreign_key})
diff --git a/lib/sqlalchemy/topological.py b/lib/sqlalchemy/topological.py
index 9e584ff4e..d061aec04 100644
--- a/lib/sqlalchemy/topological.py
+++ b/lib/sqlalchemy/topological.py
@@ -161,21 +161,20 @@ def _sort(tuples, allitems, allow_cycles=False, ignore_self_cycles=False):
edges = _EdgeCollection()
for item in list(allitems) + [t[0] for t in tuples] + [t[1] for t in tuples]:
- item_id = id(item)
- if item_id not in nodes:
- nodes[item_id] = _Node(item)
+ if item not in nodes:
+ nodes[item] = _Node(item)
for t in tuples:
- id0, id1 = id(t[0]), id(t[1])
- if t[0] is t[1]:
+ t0, t1 = t[0], t[1]
+ if t0 is t1:
if allow_cycles:
- n = nodes[id0]
+ n = nodes[t0]
n.cycles = set([n])
elif not ignore_self_cycles:
raise CircularDependencyError("Self-referential dependency detected: %r" % t)
continue
- childnode = nodes[id1]
- parentnode = nodes[id0]
+ childnode = nodes[t1]
+ parentnode = nodes[t0]
edges.add((parentnode, childnode))
queue = []
@@ -207,11 +206,11 @@ def _sort(tuples, allitems, allow_cycles=False, ignore_self_cycles=False):
continue
else:
# long cycles not allowed
- raise CircularDependencyError("Circular dependency detected: %r %r " % (edges, queue))
+ raise CircularDependencyError("Circular dependency detected: %r" % edges)
node = queue.pop()
if not hasattr(node, '_cyclical'):
output.append(node)
- del nodes[id(node.item)]
+ del nodes[node.item]
for childnode in edges.pop_node(node):
queue.append(childnode)
return output