Refs #33288 -- Made SQLite introspection raise DatabaseError on nonexistent tables.

All the other backends behave this way and we had to make adjustments
to our test suite to account for this discrepancy.

This also allows SQLite's get_relations() not to raise on a nonexistent
table while making sure the InspectDBTestCase.test_introspection_errors
test which ensures an error during introspection is surfaced in
generated models files still passes.
This commit is contained in:
Simon Charette 2021-11-13 19:22:36 -05:00 committed by Mariusz Felisiak
parent 8d9827c06c
commit 30ec7fe89a
2 changed files with 3 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from collections import namedtuple
import sqlparse import sqlparse
from django.db import DatabaseError
from django.db.backends.base.introspection import ( from django.db.backends.base.introspection import (
BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo, BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
) )
@ -84,6 +85,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
""" """
cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(table_name)) cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(table_name))
table_info = cursor.fetchall() table_info = cursor.fetchall()
if not table_info:
raise DatabaseError(f'Table {table_name} does not exist (empty pragma).')
collations = self._get_column_collations(cursor, table_name) collations = self._get_column_collations(cursor, table_name)
json_columns = set() json_columns = set()
if self.connection.features.can_introspect_json_field: if self.connection.features.can_introspect_json_field:

View File

@ -119,9 +119,6 @@ class SchemaTests(TransactionTestCase):
for name, (type, desc) in columns.items(): for name, (type, desc) in columns.items():
if isinstance(type, tuple): if isinstance(type, tuple):
columns[name] = (type[0], desc) columns[name] = (type[0], desc)
# SQLite also doesn't error properly
if not columns:
raise DatabaseError("Table does not exist (empty pragma)")
return columns return columns
def get_primary_key(self, table): def get_primary_key(self, table):