diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 16:42:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 16:42:26 -0400 |
| commit | cc57ea495f6460dd56daa6de57e40047ed999369 (patch) | |
| tree | 837f5a84363c387d7f8fdeabc06928cd078028e1 /test/sql/test_selectable.py | |
| parent | 2a946254023135eddd222974cf300ffaa5583f02 (diff) | |
| download | sqlalchemy-cc57ea495f6460dd56daa6de57e40047ed999369.tar.gz | |
Robustness for lambdas, lambda statements
in order to accommodate relationship loaders
with lambda caching, a lot more is needed. This is
a full refactor of the lambda system such that it
now has two levels of caching; the first level caches what
can be known from the __code__ element, then the next level
of caching is against the lambda itself and the contents
of __closure__. This allows for the elements inside
the lambdas, like columns and entities, to change and
then be part of the cache key. Lazy/selectinloads' use of
baked queries had to add distinct cache key elements,
which was attempted here but overall things needed to be
more robust than that.
This commit is broken out from the very long and sprawling
commit at Id6b5c03b1ce9ddb7b280f66792212a0ef0a1c541 .
Change-Id: I29a513c98917b1d503abfdd61e6b6e8800851aa8
Diffstat (limited to 'test/sql/test_selectable.py')
| -rw-r--r-- | test/sql/test_selectable.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 01c8d7ca6..58280bb67 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -29,6 +29,7 @@ from sqlalchemy import TypeDecorator from sqlalchemy import union from sqlalchemy import util from sqlalchemy.sql import Alias +from sqlalchemy.sql import annotation from sqlalchemy.sql import base from sqlalchemy.sql import column from sqlalchemy.sql import elements @@ -2352,6 +2353,33 @@ class AnnotationsTest(fixtures.TestBase): annot = obj._annotate({}) ne_(set([obj]), set([annot])) + def test_replacement_traverse_preserve(self): + """test that replacement traverse that hits an unannotated column + does not use it when replacing an annotated column. + + this requires that replacement traverse store elements in the + "seen" hash based on id(), not hash. + + """ + t = table("t", column("x")) + + stmt = select([t.c.x]) + + whereclause = annotation._deep_annotate(t.c.x == 5, {"foo": "bar"}) + + eq_(whereclause._annotations, {"foo": "bar"}) + eq_(whereclause.left._annotations, {"foo": "bar"}) + eq_(whereclause.right._annotations, {"foo": "bar"}) + + stmt = stmt.where(whereclause) + + s2 = visitors.replacement_traverse(stmt, {}, lambda elem: None) + + whereclause = s2._where_criteria[0] + eq_(whereclause._annotations, {"foo": "bar"}) + eq_(whereclause.left._annotations, {"foo": "bar"}) + eq_(whereclause.right._annotations, {"foo": "bar"}) + def test_proxy_set_iteration_includes_annotated(self): from sqlalchemy.schema import Column |
