criteria which will join via AND, i.e.
query.filter(x==y, z>q, ...)
+ - Fixed regression from 0.6 whereby if
+ "load_on_pending" relationship() flag were used
+ where a non-"get()" lazy clause needed to be
+ emitted on a pending object, it would fail
+ to load.
+
- engine
- [bug] Added __reduce__ to StatementError,
DBAPIError so that exceptions are pickleable,
raise exc.InvalidRequestError(
"A value is required for bind parameter %r"
% bindparam.key)
- elif bindparam.callable:
- pd[name] = bindparam.callable()
else:
- pd[name] = bindparam.value
+ pd[name] = bindparam.effective_value
return pd
else:
pd = {}
for bindparam in self.bind_names:
- if bindparam.callable:
- pd[self.bind_names[bindparam]] = bindparam.callable()
- else:
- pd[self.bind_names[bindparam]] = bindparam.value
+ pd[self.bind_names[bindparam]] = bindparam.effective_value
return pd
params = property(construct_params, doc="""
else:
self.type = type_
+ @property
+ def effective_value(self):
+ """Return the value of this bound parameter,
+ taking into account if the ``callable`` parameter
+ was set.
+
+ The ``callable`` value will be evaluated
+ and returned if present, else ``value``.
+
+ """
+ if self.callable:
+ return self.callable()
+ else:
+ return self.value
+
def _clone(self):
c = ClauseElement._clone(self)
if self.unique:
v = []
def visit_bindparam(bind):
- value = bind.value
-
- # evaluate callables
- if callable(value):
- value = value()
-
- v.append(value)
+ v.append(bind.effective_value)
visitors.traverse(clause, {}, {'bindparam':visit_bindparam})
return v
# ...unless the flag is on
assert c3.parent is p1
+ def test_collection_load_from_pending_populated(self):
+ Parent.children.property.load_on_pending = True
+ p2 = Parent(id=p1.id)
+ sess.add(p2)
+ # load should emit since PK is populated
+ def go():
+ assert p2.children
+ self.assert_sql_count(testing.db, go, 1)
+
+ def test_collection_load_from_pending_no_sql(self):
+ Parent.children.property.load_on_pending = True
+ p2 = Parent(id=None)
+ sess.add(p2)
+ # load should not emit since "None" is the bound
+ # param list
+ def go():
+ assert not p2.children
+ self.assert_sql_count(testing.db, go, 0)
+
def test_load_on_pending_with_set(self):
Child.parent.property.load_on_pending = True