From fe250af8eb7294f08f491b3c1af9cf86a769f78c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 12 Sep 2010 19:18:08 -0400 Subject: - lazy loads for relationship attributes now use the current state, not the "committed" state, of foreign and primary key attributes when issuing SQL, if a flush is not in process. Previously, only the database-committed state would be used. In particular, this would cause a many-to-one get()-on-lazyload operation to fail, as autoflush is not triggered on these loads when the attributes are determined and the "committed" state may not be available. [ticket:1910] - A new flag on relationship(), load_on_pending, allows the lazy loader to fire off on pending objects without a flush taking place, as well as a transient object that's been manually "attached" to the session. Note that this flag blocks attribute events from taking place when an object is loaded, so backrefs aren't available until after a flush. The flag is only intended for very specific use cases. --- lib/sqlalchemy/sql/util.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/sqlalchemy/sql/util.py') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index c999ab786..bd4f70247 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -92,6 +92,31 @@ def find_columns(clause): visitors.traverse(clause, {}, {'column':cols.add}) return cols +def bind_values(clause): + """Return an ordered list of "bound" values in the given clause. + + E.g.:: + + >>> expr = and_( + ... table.c.foo==5, table.c.foo==7 + ... ) + >>> bind_values(expr) + [5, 7] + """ + + v = [] + def visit_bindparam(bind): + value = bind.value + + # evaluate callables + if callable(value): + value = value() + + v.append(value) + + visitors.traverse(clause, {}, {'bindparam':visit_bindparam}) + return v + def _quote_ddl_expr(element): if isinstance(element, basestring): element = element.replace("'", "''") -- cgit v1.2.1