Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Sqlite ProgramingError Exception #1106

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ if [[ $test = false ]]; then

# Read output from tail; wait for kill or stop command (docker waits here)
wait
fi
fi
18 changes: 11 additions & 7 deletions tests/unit_tests/test_tethys_apps/test_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion tethys_apps/harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down