diff --git a/corehq/apps/userreports/sql/adapter.py b/corehq/apps/userreports/sql/adapter.py index 2437acf301c3..d06d5424ec87 100644 --- a/corehq/apps/userreports/sql/adapter.py +++ b/corehq/apps/userreports/sql/adapter.py @@ -58,8 +58,10 @@ def get_table(self): @memoized def get_existing_table_from_db(self): """Loads existing table directly from database if one exists""" - if self.table_exists: + try: return sqlalchemy.Table(self.get_table().name, sqlalchemy.MetaData(), autoload_with=self.engine) + except sqlalchemy.exc.NoSuchTableError: + pass @property def table_exists(self): diff --git a/corehq/apps/userreports/tasks.py b/corehq/apps/userreports/tasks.py index c363fffa15d2..4a8e76f93cad 100644 --- a/corehq/apps/userreports/tasks.py +++ b/corehq/apps/userreports/tasks.py @@ -159,9 +159,9 @@ def rebuild_indicators_in_place(indicator_config_id, initiated_by=None, source=N def _get_rows_count_from_existing_table(adapter): - if not adapter.table_exists: - return None table = adapter.get_existing_table_from_db() + if not table: + return None return adapter.session_helper.Session.query(table).count()