From 27c4bbec352be457f392eb1ca44e78435adddcf6 Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Thu, 28 Dec 2023 15:32:22 +0545 Subject: [PATCH] Add validation for empty category and params --- API/hdx.py | 21 ++++++++++++++++----- src/app.py | 5 +++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/API/hdx.py b/API/hdx.py index f117e0b0..d5fdd486 100644 --- a/API/hdx.py +++ b/API/hdx.py @@ -164,7 +164,9 @@ async def process_custom_requests( ], "where": "tags['building'] IS NOT NULL", "formats": ["geojson", "shp", "kml"], - }, + } + }, + { "Roads": { "types": ["lines"], "select": [ @@ -181,7 +183,9 @@ async def process_custom_requests( ], "where": "tags['highway'] IS NOT NULL", "formats": ["geojson", "shp", "kml"], - }, + } + }, + { "Waterways": { "types": ["lines", "polygons"], "select": [ @@ -199,14 +203,16 @@ async def process_custom_requests( ], "where": "tags['waterway'] IS NOT NULL OR tags['water'] IS NOT NULL OR tags['natural'] IN ('water','wetland','bay')", "formats": ["geojson", "shp", "kml"], - }, + } + }, + { "Landuse": { "types": ["points", "polygons"], "select": ["name", "amenity", "landuse", "leisure"], "where": "tags['landuse'] IS NOT NULL", "formats": ["geojson", "shp", "kml"], - }, - } + } + }, ], }, }, @@ -783,6 +789,11 @@ async def process_custom_requests( status_code=403, detail=[{"msg": "Insufficient Permission to choose queue"}], ) + params.categories = [category for category in params.categories if category] + if len(params.categories) == 0: + raise HTTPException( + status_code=400, detail=[{"msg": "Categories can't be empty"}] + ) task = process_hdx_request.apply_async( args=(params.model_dump(),), queue=queue_name, track_started=True ) diff --git a/src/app.py b/src/app.py index 3d9c4c2f..1b511c90 100644 --- a/src/app.py +++ b/src/app.py @@ -1572,9 +1572,14 @@ def process_hdx_tags(self): """ started_at = datetime.now().isoformat() processing_time_start = time.time() + # clean cateories remove {} + self.params.categories = [ + category for category in self.params.categories if category + ] table_type = [ cat_type for category in self.params.categories + if category for cat_type in list(category.values())[0].types ] where_0_category = None