diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-14 12:12:08 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-14 12:14:12 -0400 |
commit | b26cf96462b195a4c12ccdf8283ef028f91eb872 (patch) | |
tree | ffaceb138fd0039863ea1110fd33d295aa66c003 /lib/sqlalchemy/engine/default.py | |
parent | d3c3982100a617623c92b41799b19f27448a1574 (diff) | |
download | sqlalchemy-b26cf96462b195a4c12ccdf8283ef028f91eb872.tar.gz |
Explicitly test for Connection in dialect.has_table()
The :meth:`_engine.Dialect.has_table` method now raises an informative
exception if a non-Connection is passed to it, as this incorrect behavior
seems to be common. This method is not intended for external use outside
of a dialect. Please use the :meth:`.Inspector.has_table` method
or for cross-compatibility with older SQLAlchemy versions, the
:meth:`_engine.Engine.has_table` method.
Fixes: #5780
Fixes: #6062
Fixes: #6260
Change-Id: I9b2439675167019b68d682edee3dcdcfce836987
Diffstat (limited to 'lib/sqlalchemy/engine/default.py')
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index d45b6d7a7..375a93a48 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -22,6 +22,7 @@ import weakref from . import characteristics from . import cursor as _cursor from . import interfaces +from .base import Connection from .. import event from .. import exc from .. import pool @@ -323,6 +324,19 @@ class DefaultDialect(interfaces.Dialect): self._encoder = codecs.getencoder(self.encoding) self._decoder = processors.to_unicode_processor_factory(self.encoding) + def _ensure_has_table_connection(self, arg): + + if not isinstance(arg, Connection): + raise exc.ArgumentError( + "The argument passed to Dialect.has_table() should be a " + "%s, got %s. " + "Additionally, the Dialect.has_table() method is for " + "internal dialect " + "use only; please use " + "``inspect(some_engine).has_table(<tablename>>)`` " + "for public API use." % (Connection, type(arg)) + ) + @util.memoized_property def _supports_statement_cache(self): return ( |