--- /dev/null
+.. change::
+ :tags: bug, mysql, regression
+ :tickets: 9251
+
+ 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.
+
+
+
+.. change::
+ :tags: bug, sqlite
+ :tickets: 9251
+
+ 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.
+
) 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
def has_table(self, connection, table_name, schema=None, **kw):
self._ensure_has_table_connection(connection)
+ if schema is not None and schema not in self.get_schema_names(
+ connection, **kw
+ ):
+ return False
+
info = self._get_table_pragma(
connection, "table_info", table_name, schema=schema
)
)
)
+ @testing.requires.schemas
+ def test_has_table_nonexistent_schema(self):
+ with config.db.begin() as conn:
+ is_false(
+ config.db.dialect.has_table(
+ conn, "test_table", schema="nonexistent_schema"
+ )
+ )
+
@testing.requires.views
def test_has_table_view(self, connection):
insp = inspect(connection)