diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-06 13:54:56 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-06 16:06:11 -0500 |
| commit | 662d6e24526bfd9d358b8a9e1906fb29bf93ef30 (patch) | |
| tree | cd473a0b48312f599ec7a7d65ef43cd617420a41 /lib/sqlalchemy/dialects/mysql | |
| parent | ce7922dfd001a0e9fc0914ec217c950acc5e0e5f (diff) | |
| download | sqlalchemy-662d6e24526bfd9d358b8a9e1906fb29bf93ef30.tar.gz | |
add error code 1049 for mysql has_table
Fixed regression caused by issue :ticket:`9058` which adjusted the MySQL
dialect's ``has_table()`` to again use "DESCRIBE", where the specific error
code raised by MySQL version 8 when using a non-existent schema name was
unexpected and failed to be interpreted as a boolean result.
Fixed the SQLite dialect's ``has_table()`` function to correctly report
False for queries that include a non-None schema name for a schema that
doesn't exist; previously, a database error was raised.
Fixes: #9251
Change-Id: I5ef9cf0887865c3c521d88bca0ba18954a108241
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 50e0ec07e..3e3578df9 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -2690,7 +2690,21 @@ class MySQLDialect(default.DefaultDialect): ) as rs: return rs.fetchone() is not None except exc.DBAPIError as e: - if self._extract_error_code(e.orig) == 1146: + # https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html # noqa: E501 + # there are a lot of codes that *may* pop up here at some point + # but we continue to be fairly conservative. We include: + # 1146: Table '%s.%s' doesn't exist - what every MySQL has emitted + # for decades + # + # mysql 8 suddenly started emitting: + # 1049: Unknown database '%s' - for nonexistent schema + # + # also added: + # 1051: Unknown table '%s' - not known to emit + # + # there's more "doesn't exist" kinds of messages but they are + # less clear if mysql 8 would suddenly start using one of those + if self._extract_error_code(e.orig) in (1146, 1049, 1051): return False raise |
