Re: [Sqlalchemy-tickets] [sqlalchemy] #2887: subqueryload query invokes ahead of parent loader init
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-12-11 17:57:12
|
#2887: subqueryload query invokes ahead of parent loader init, can cause conflicts
------------------------------+-------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: defect | Status: new
Priority: high | Milestone: 0.8.xx
Component: orm | Severity: major - 1-3 hours
Resolution: | Keywords:
Progress State: in progress |
------------------------------+-------------------------------
Comment (by zzzeek):
whew, no problem, that was just because we were testing _dict being empty,
which it might be anyway, here's an even more crude "with a flag" thing,
obviously need to clean this up:
{{{
#!diff
diff --git a/lib/sqlalchemy/orm/strategies.py
b/lib/sqlalchemy/orm/strategies.py
index 8226a0e..2f20040 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -937,12 +937,22 @@ class SubqueryLoader(AbstractRelationshipLoader):
# call upon create_row_processor again
collections = path.get(context.attributes, "collections")
if collections is None:
- collections = dict(
- (k, [vv[0] for vv in v])
- for k, v in itertools.groupby(
- subq,
- lambda x: x[1:]
- ))
+ flag = [0]
+ _data = dict()
+ #subq = list(subq)
+ class X(object):
+ def get(self, key, default):
+ if not flag[0]:
+ flag[0] = 1
+ _data.update(
+ (k, [vv[0] for vv in v])
+ for k, v in itertools.groupby(
+ subq,
+ lambda x: x[1:]
+ )
+ )
+ return _data.get(key, default)
+ collections = X()
path.set(context.attributes, 'collections', collections)
if adapter:
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2887#comment:3>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|