Update utils.py (#225)

* Update utils.py

verify get_meta isn't none before requesting db_table

* Add passenv to tox.ini

* Fix test_explain in sqlite

---------

Co-authored-by: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com>
This commit is contained in:
David Haas 2023-03-12 16:39:04 -04:00 committed by GitHub
parent 52406ec111
commit 866b662273
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View file

@ -907,7 +907,7 @@ class ReadTestCase(TestUtilsMixin, TransactionTestCase):
def test_explain(self):
explain_kwargs = {}
if self.is_sqlite:
expected = (r'\d+ 0 0 SCAN TABLE cachalot_test\n'
expected = (r'\d+ 0 0 SCAN cachalot_test\n'
r'\d+ 0 0 USE TEMP B-TREE FOR ORDER BY')
elif self.is_mysql:
if self.django_version < (3, 1):

View file

@ -217,7 +217,8 @@ def _get_tables(db_alias, query, compiler=False):
# Gets all tables already found by the ORM.
tables = set(query.table_map)
tables.add(query.get_meta().db_table)
if query.get_meta():
tables.add(query.get_meta().db_table)
# Gets tables in subquery annotations.
for annotation in query.annotations.values():

View file

@ -7,6 +7,7 @@ envlist =
py{38,39,310}-djangomain-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased},
[testenv]
passenv = *
basepython =
py37: python3.7
py38: python3.8