From 69bacc86d7b508cefbe99a0295a2ea09e50723b2 Mon Sep 17 00:00:00 2001 From: Sudan Bhandari Date: Mon, 11 Nov 2024 10:27:01 +0545 Subject: [PATCH] PR Fixes --- apps/geo/models.py | 12 ++++++------ apps/geo/tasks.py | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/geo/models.py b/apps/geo/models.py index 4d8a54e0e..bf45cd3d3 100644 --- a/apps/geo/models.py +++ b/apps/geo/models.py @@ -14,11 +14,11 @@ class Region(UserResource): - class Status(models.TextChoices): - INITIATED = 'initiated', 'Initiated' - PENDING = 'pending', 'Pending' - COMPLETED = 'completed', 'Completed' - FAILED = 'failed', 'Failed' + class Status(models.IntegerChoices): + INITIATED = 0, 'Initiated' + PENDING = 1, 'Pending' + COMPLETED = 2, 'Completed' + FAILED = 3, 'Failed' """ Region model @@ -40,7 +40,7 @@ class Status(models.TextChoices): cache_index = models.SmallIntegerField(default=0) # Used to track cache update. centroid = models.PointField(blank=True, null=True) # Admin level 0 centroid geo_options = models.JSONField(default=None, blank=True, null=True) - status = models.CharField(max_length=30, choices=Status.choices, default=Status.PENDING) + status = models.PositiveSmallIntegerField(choices=Status.choices, default=Status.PENDING) def __init__(self, *args, **kwargs): self.id: Union[int, None] diff --git a/apps/geo/tasks.py b/apps/geo/tasks.py index d49a75ca8..8750e4f30 100644 --- a/apps/geo/tasks.py +++ b/apps/geo/tasks.py @@ -181,7 +181,10 @@ def _load_geo_areas(region_id): Basically, it starts with root admin level and iterate through all the children. """ - region = Region.objects.get(pk=region_id) + region = Region.objects.filter(pk=region_id).first() + if not region: + logger.error("Region not found", exc_info=True) + return False try: with reversion.create_revision(): if AdminLevel.objects.filter(region=region).count() == 0: