summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-08-18 15:34:23 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-08-18 15:34:23 -0400
commit676876f4668520af267d7db883d9486a8924b320 (patch)
tree24656c990a2f9bec54e8e2e3730a1ddc4d77c304 /lib/sqlalchemy/util
parentc5792c277bb658974baff9ddb5c00e589de10c99 (diff)
downloadsqlalchemy-676876f4668520af267d7db883d9486a8924b320.tar.gz
Fixed a potential issue in an ordered sequence implementation used
by the ORM to iterate mapper hierarchies; under the Jython interpreter this implementation wasn't ordered, even though cPython and Pypy maintained ordering. Also in 0.8.3. [ticket:2794]
Diffstat (limited to 'lib/sqlalchemy/util')
-rw-r--r--lib/sqlalchemy/util/_collections.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py
index c3b44abae..b2e5c6250 100644
--- a/lib/sqlalchemy/util/_collections.py
+++ b/lib/sqlalchemy/util/_collections.py
@@ -650,18 +650,23 @@ class IdentitySet(object):
class WeakSequence(object):
def __init__(self, elements):
- self._storage = weakref.WeakValueDictionary(
- (idx, element) for idx, element in enumerate(elements)
- )
+ self._storage = [
+ weakref.ref(element) for element in elements
+ ]
+
+ def _remove(self, ref):
+ self._storage.remove(ref)
def __iter__(self):
- return iter(self._storage.values())
+ return (obj for obj in (ref() for ref in self._storage) if obj is not None)
def __getitem__(self, index):
try:
- return self._storage[index]
+ obj = self._storage[index]
except KeyError:
raise IndexError("Index %s out of range" % index)
+ else:
+ return obj()
class OrderedIdentitySet(IdentitySet):