Skip to content

Commit

Permalink
check table exists before loading from db
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Sep 25, 2023
1 parent dbfa701 commit 2f3f4da
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions care/facility/static_data/icd11.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import json

from django.db.utils import ProgrammingError
from django.db import connection
from littletable import Table

from care.facility.models.icd11_diagnosis import ICD11Diagnosis
Expand All @@ -13,10 +13,11 @@ def fetch_data():


def fetch_from_db():
try:
# This is a hack to prevent the migration from failing when the table does not exist
all_tables = set(connection.introspection.table_names())
if set("facility_icd11diagnosis") & all_tables:
return ICD11Diagnosis.objects.all().values("id", "label")

Check warning on line 19 in care/facility/static_data/icd11.py

View check run for this annotation

Codecov / codecov/patch

care/facility/static_data/icd11.py#L19

Added line #L19 was not covered by tests
except ProgrammingError as e:
print(e)
else:
return []


Expand Down

0 comments on commit 2f3f4da

Please sign in to comment.