From da1d12a9192e92a42aade8a96ed978f21d1ca6c0 Mon Sep 17 00:00:00 2001 From: Gio <43544549+romer8@users.noreply.github.com> Date: Mon, 28 Oct 2024 08:24:59 -0600 Subject: [PATCH] Check for Sqlite ProgramingError Exception (#1106) * fix for sqlite programming error that is triggered when harvesting apps * added test * merge Programming errors * fix run.sh if statements order * removed changes to the run.sh --------- Co-authored-by: romer8 --- docker/run.sh | 2 +- .../test_tethys_apps/test_harvester.py | 18 +++++++++++------- tethys_apps/harvester.py | 7 ++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docker/run.sh b/docker/run.sh index 0962f82ff..8636e993b 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -135,4 +135,4 @@ if [[ $test = false ]]; then # Read output from tail; wait for kill or stop command (docker waits here) wait -fi +fi \ No newline at end of file diff --git a/tests/unit_tests/test_tethys_apps/test_harvester.py b/tests/unit_tests/test_tethys_apps/test_harvester.py index fd8c83453..4627a8ff6 100644 --- a/tests/unit_tests/test_tethys_apps/test_harvester.py +++ b/tests/unit_tests/test_tethys_apps/test_harvester.py @@ -4,6 +4,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.db.utils import ProgrammingError +from sqlite3 import ProgrammingError as SqliteProgrammingError from tethys_apps.harvester import SingletonHarvester from tethys_apps.base.testing.environment import set_testing_environment @@ -296,16 +297,19 @@ def test_harvest_app_instances_programming_error( :return: """ list_apps = {"test_app": "tethysapp.test_app"} + exceptions = [ProgrammingError, SqliteProgrammingError] - mock_permissions.side_effect = ProgrammingError + for exception in exceptions: + with self.subTest(exception=exception): + mock_permissions.side_effect = exception - shv = SingletonHarvester() - shv._harvest_app_instances(list_apps) + shv = SingletonHarvester() + shv._harvest_app_instances(list_apps) - mock_logwarning.assert_called() - mock_permissions.assert_called() - self.assertIn("Tethys Apps Loaded:", mock_stdout.getvalue()) - self.assertIn("test_app", mock_stdout.getvalue()) + mock_logwarning.assert_called() + mock_permissions.assert_called() + self.assertIn("Tethys Apps Loaded:", mock_stdout.getvalue()) + self.assertIn("test_app", mock_stdout.getvalue()) @mock.patch("sys.stdout", new_callable=io.StringIO) @mock.patch("tethys_apps.harvester.tethys_log.warning") diff --git a/tethys_apps/harvester.py b/tethys_apps/harvester.py index 47f6e0ec0..60d67645b 100644 --- a/tethys_apps/harvester.py +++ b/tethys_apps/harvester.py @@ -11,7 +11,7 @@ import inspect import logging import pkgutil - +from sqlite3 import ProgrammingError as SqliteProgrammingError from django.db.utils import ProgrammingError from django.core.exceptions import ObjectDoesNotExist from tethys_apps.base import TethysAppBase, TethysExtensionBase @@ -323,6 +323,11 @@ def _harvest_app_instances(self, app_packages_list): "Unable to register app permissions. django_content_type " "table does not exist" ) + except SqliteProgrammingError: + tethys_log.warning( + "Unable to register app permissions. django_content_type " + "table does not exist in sqlite3" + ) except ObjectDoesNotExist as e: tethys_log.warning(e)