diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/base.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/traversals.py | 18 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/visitors.py | 2 |
3 files changed, 26 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 6d65d9061..8ff907ef0 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -781,7 +781,10 @@ class Executable(roles.StatementRole, Generative): _executable_traverse_internals = [ ("_with_options", InternalTraversal.dp_executable_options), - ("_with_context_options", ExtendedInternalTraversal.dp_plain_obj), + ( + "_with_context_options", + ExtendedInternalTraversal.dp_with_context_options, + ), ("_propagate_attrs", ExtendedInternalTraversal.dp_propagate_attrs), ] @@ -853,8 +856,8 @@ class Executable(roles.StatementRole, Generative): These are callable functions that will be given the CompileState object upon compilation. - A second argument cache_args is required, which will be combined - with the identity of the function itself in order to produce a + A second argument cache_args is required, which will be combined with + the ``__code__`` identity of the function itself in order to produce a cache key. """ diff --git a/lib/sqlalchemy/sql/traversals.py b/lib/sqlalchemy/sql/traversals.py index e8a805285..e64eff6a4 100644 --- a/lib/sqlalchemy/sql/traversals.py +++ b/lib/sqlalchemy/sql/traversals.py @@ -310,6 +310,12 @@ class CacheKey(namedtuple("CacheKey", ["key", "bindparams"])): def __eq__(self, other): return self.key == other.key + @classmethod + def _diff_tuples(cls, left, right): + ck1 = CacheKey(left, []) + ck2 = CacheKey(right, []) + return ck1._diff(ck2) + def _whats_different(self, other): k1 = self.key @@ -413,6 +419,11 @@ class _CacheKey(ExtendedInternalTraversal): visit_propagate_attrs = PROPAGATE_ATTRS + def visit_with_context_options( + self, attrname, obj, parent, anon_map, bindparams + ): + return tuple((fn.__code__, c_key) for fn, c_key in obj) + def visit_inspectable(self, attrname, obj, parent, anon_map, bindparams): return (attrname, inspect(obj)._gen_cache_key(anon_map, bindparams)) @@ -1209,6 +1220,13 @@ class TraversalComparatorStrategy(InternalTraversal, util.MemoizedSlots): else: return left == right + def visit_with_context_options( + self, attrname, left_parent, left, right_parent, right, **kw + ): + return tuple((fn.__code__, c_key) for fn, c_key in left) == tuple( + (fn.__code__, c_key) for fn, c_key in right + ) + def visit_plain_obj( self, attrname, left_parent, left, right_parent, right, **kw ): diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 5d60774aa..793e7fc5c 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -272,6 +272,8 @@ class InternalTraversal(util.with_metaclass(_InternalTraversalType, object)): dp_executable_options = symbol("EO") + dp_with_context_options = symbol("WC") + dp_fromclause_ordered_set = symbol("CO") """Visit an ordered set of :class:`_expression.FromClause` objects. """ |
