From: Mike Bayer Date: Sun, 12 Dec 2010 04:55:10 +0000 (-0500) Subject: slight shrinking of the iterable X-Git-Tag: rel_0_7b1~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57b95f45536e1f9c4450d118f0fb2534606b6f2a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git slight shrinking of the iterable --- diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 127f070cc8..2a9d3760b1 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -22,6 +22,7 @@ from itertools import chain import sqlalchemy.exceptions as sa_exc from sqlalchemy import log, util, event from sqlalchemy.sql import expression +deque = util.importlater('collections').deque mapperutil = util.importlater('sqlalchemy.orm', 'util') @@ -453,7 +454,7 @@ class PropertyOption(MapperOption): [str(m.path_entity) for m in query._entities])) else: return None - + def _get_paths(self, query, raiseerr): path = None entity = None @@ -465,14 +466,14 @@ class PropertyOption(MapperOption): current_path = list(query._current_path) - tokens = [] - for key in util.to_list(self.key): - if isinstance(key, basestring): - tokens += key.split('.') - else: - tokens += [key] - for token in tokens: + tokens = deque(self.key) + while tokens: + token = tokens.popleft() if isinstance(token, basestring): + sub_tokens = token.split(".", 1) + token = sub_tokens[0] + tokens.extendleft(sub_tokens[1:]) + if not entity: if current_path: if current_path[1] == token: diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index f23145da55..1cea5349a9 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -656,7 +656,7 @@ class LoadLazyAttribute(object): if rev.direction is interfaces.MANYTOONE and \ rev._use_get and \ not isinstance(rev.strategy, LazyLoader): - q = q.options(EagerLazyOption(rev.key, lazy='select')) + q = q.options(EagerLazyOption((rev.key,), lazy='select')) if state.load_options: q = q._conditional_options(*state.load_options) diff --git a/test/orm/test_query.py b/test/orm/test_query.py index b6d9947b4c..cd0deee2ec 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -2106,5 +2106,3 @@ class OptionsTest(QueryTest): opt = self._option_fixture(Address.user, User.addresses) self._assert_path_result(opt, q, [], []) - -