From 866b662273df63cdfe3e34de8667fa07765bb992 Mon Sep 17 00:00:00 2001 From: David Haas <63743025+hho6643@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:39:04 -0400 Subject: [PATCH] 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> --- cachalot/tests/read.py | 2 +- cachalot/utils.py | 3 ++- tox.ini | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cachalot/tests/read.py b/cachalot/tests/read.py index f45072f..a08237e 100644 --- a/cachalot/tests/read.py +++ b/cachalot/tests/read.py @@ -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): diff --git a/cachalot/utils.py b/cachalot/utils.py index a20d2a6..9df2a74 100644 --- a/cachalot/utils.py +++ b/cachalot/utils.py @@ -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(): diff --git a/tox.ini b/tox.ini index 8e200ec..166b359 100644 --- a/tox.ini +++ b/tox.ini @@ -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