summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2019-10-31 15:56:02 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2019-10-31 15:56:02 +0000
commitdb47859dca999b9d1679b513fe855e408d7d07c4 (patch)
treea0198a2e5f41183061582ea6b671145c3a5e14dd
parenta71fe131a45d3f51b2ecc5338e0851c20f9277b7 (diff)
parent9fc54801c8235a6327e0ce80b145f7ba756ae47a (diff)
downloadsqlalchemy-db47859dca999b9d1679b513fe855e408d7d07c4.tar.gz
Merge "Cache every key in reflection_cache"
-rw-r--r--doc/build/changelog/unreleased_13/4955.rst12
-rw-r--r--lib/sqlalchemy/engine/reflection.py6
-rw-r--r--test/dialect/postgresql/test_reflection.py11
3 files changed, 24 insertions, 5 deletions
diff --git a/doc/build/changelog/unreleased_13/4955.rst b/doc/build/changelog/unreleased_13/4955.rst
new file mode 100644
index 000000000..7e98c4849
--- /dev/null
+++ b/doc/build/changelog/unreleased_13/4955.rst
@@ -0,0 +1,12 @@
+.. change::
+ :tags: bug, engine, postgresql
+ :tickets: 4955
+
+ Fixed bug in :class:`.Inspector` where the cache key generation did not
+ take into account arguments passed in the form of tuples, such as the tuple
+ of view name styles to return for the PostgreSQL dialect. This would lead
+ the inspector to cache too generally for a more specific set of criteria.
+ The logic has been adjusted to include every keyword element in the cache,
+ as every argument is expected to be appropriate for a cache else the
+ caching decorator should be bypassed by the dialect.
+
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index e36d99d5d..15300c6a1 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -45,11 +45,7 @@ def cache(fn, self, con, *args, **kw):
key = (
fn.__name__,
tuple(a for a in args if isinstance(a, util.string_types)),
- tuple(
- (k, v)
- for k, v in kw.items()
- if isinstance(v, util.string_types + util.int_types + (float,))
- ),
+ tuple((k, v) for k, v in kw.items() if k != "info_cache"),
)
ret = info_cache.get(key)
if ret is None:
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py
index 7054a9fdd..b6cedd55f 100644
--- a/test/dialect/postgresql/test_reflection.py
+++ b/test/dialect/postgresql/test_reflection.py
@@ -232,6 +232,17 @@ class MaterializedViewReflectionTest(
set(["test_mview"]),
)
+ def test_get_view_names_reflection_cache_ok(self):
+ insp = inspect(testing.db)
+ eq_(
+ set(insp.get_view_names(include=("plain",))), set(["test_regview"])
+ )
+ eq_(
+ set(insp.get_view_names(include=("materialized",))),
+ set(["test_mview"]),
+ )
+ eq_(set(insp.get_view_names()), set(["test_regview", "test_mview"]))
+
def test_get_view_names_empty(self):
insp = inspect(testing.db)
assert_raises(ValueError, insp.get_view_names, include=())