summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-02-24 10:44:14 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-02-24 10:47:05 -0500
commit996654df341a30b539434bb4fd1e0d53f46641a0 (patch)
treee3b0c59b3f4752df03ecd47b039997e98c4627d0 /test
parentca16c53651f819e9587ed29d7d1d7d937e7f25ce (diff)
downloadsqlalchemy-996654df341a30b539434bb4fd1e0d53f46641a0.tar.gz
Ensure schema-level table includes annotations in caching
In 29330ec159 we ensured that annotations are part of cache keys. However we failed to do so for the schema-level Table which will definitely need to distinguish between ORM and non-ORM annotated tables when caching, so ensure this is part of the cache key. Change-Id: I8d996873f2d7fa63230ef837db7e69a0101973b2
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_compare.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py
index 2d0e39331..c59462845 100644
--- a/test/sql/test_compare.py
+++ b/test/sql/test_compare.py
@@ -168,6 +168,25 @@ class CoreFixtures(object):
),
),
lambda: (
+ table_a,
+ table_a._annotate({"orm": True}),
+ table_a._annotate({"orm": True})._annotate({"bar": False}),
+ table_a._annotate(
+ {"orm": True, "parententity": MyEntity("a", table_a)}
+ ),
+ table_a._annotate(
+ {"orm": True, "parententity": MyEntity("b", table_a)}
+ ),
+ table_a._annotate(
+ {"orm": True, "parententity": MyEntity("b", select([table_a]))}
+ ),
+ ),
+ lambda: (
+ table("a", column("x"), column("y")),
+ table("a", column("x"), column("y"))._annotate({"orm": True}),
+ table("b", column("x"), column("y"))._annotate({"orm": True}),
+ ),
+ lambda: (
cast(column("q"), Integer),
cast(column("q"), Float),
cast(column("p"), Integer),
@@ -776,7 +795,27 @@ class CompareClausesTest(fixtures.TestBase):
ne_(t1._generate_cache_key(), t2._generate_cache_key())
- eq_(t1._generate_cache_key().key, (t1,))
+ eq_(t1._generate_cache_key().key, (t1, "_annotations", ()))
+
+ def test_compare_metadata_tables_annotations(self):
+ # metadata Table objects cache on their own identity, not their
+ # structure. This is mainly to reduce the size of cache keys
+ # as well as reduce computational overhead, as Table objects have
+ # very large internal state and they are also generally global
+ # objects.
+
+ t1 = Table("a", MetaData(), Column("q", Integer), Column("p", Integer))
+ t2 = Table("a", MetaData(), Column("q", Integer), Column("p", Integer))
+
+ t1 = t1._annotate({"orm": True})
+ t2 = t2._annotate({"orm": True})
+
+ ne_(t1._generate_cache_key(), t2._generate_cache_key())
+
+ eq_(
+ t1._generate_cache_key().key,
+ (t1, "_annotations", (("orm", True),)),
+ )
def test_compare_adhoc_tables(self):
# non-metadata tables compare on their structure. these objects are