Skip to content

Commit

Permalink
Check for Sqlite ProgramingError Exception (#1106)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
romer8 and romer8 authored Oct 28, 2024
1 parent d4a8761 commit da1d12a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
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

0 comments on commit da1d12a

Please sign in to comment.