From 11d5430021f26fd28b1678b638d5fbc4f40b5f7e Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Wed, 6 Nov 2024 18:13:38 +0545 Subject: [PATCH] fix(backend): s3 upload and db insertion for submission photos (#1856) * fix: s3 upload and db insertion for submission photos * fix: split-by-square, changed payload dimension to dimension_meters --- src/backend/app/db/models.py | 2 +- src/backend/app/submissions/submission_crud.py | 3 ++- src/backend/app/submissions/submission_routes.py | 1 + src/frontend/src/api/CreateProjectService.ts | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/app/db/models.py b/src/backend/app/db/models.py index 5273974445..4c64afa5fc 100644 --- a/src/backend/app/db/models.py +++ b/src/backend/app/db/models.py @@ -1620,7 +1620,7 @@ class DbSubmissionPhoto(BaseModel): TODO SQL this will be replace by ODK Central direct S3 upload. """ - id: int + id: Optional[int] = None project_id: Optional[int] = None task_id: Optional[int] = None # Note this is not a DbTask, but an ODK task_id submission_id: Optional[str] = None diff --git a/src/backend/app/submissions/submission_crud.py b/src/backend/app/submissions/submission_crud.py index ab571ce19d..56bcf6a996 100644 --- a/src/backend/app/submissions/submission_crud.py +++ b/src/backend/app/submissions/submission_crud.py @@ -344,7 +344,7 @@ async def upload_attachment_to_s3( # Perform batch insert if there are new records to insert async with db.cursor() as cur: - await cur.execute( + await cur.executemany( # executes multiple inserts (batch insert) """ INSERT INTO submission_photos ( project_id, @@ -358,6 +358,7 @@ async def upload_attachment_to_s3( """, batch_insert_data, ) + db.commit() return True except Exception as e: diff --git a/src/backend/app/submissions/submission_routes.py b/src/backend/app/submissions/submission_routes.py index d2a65df633..ab322fc15f 100644 --- a/src/backend/app/submissions/submission_routes.py +++ b/src/backend/app/submissions/submission_routes.py @@ -321,6 +321,7 @@ async def submission_table( project.id, instance_ids, background_task_id, + db, ) if task_id: diff --git a/src/frontend/src/api/CreateProjectService.ts b/src/frontend/src/api/CreateProjectService.ts index 9f9748f764..a6ea36d25e 100755 --- a/src/frontend/src/api/CreateProjectService.ts +++ b/src/frontend/src/api/CreateProjectService.ts @@ -292,7 +292,7 @@ const GetDividedTaskFromGeojson = (url: string, projectData: Record try { const dividedTaskFormData = new FormData(); dividedTaskFormData.append('project_geojson', projectData.geojson); - dividedTaskFormData.append('dimension', projectData.dimension); + dividedTaskFormData.append('dimension_meters', projectData.dimension); const getGetDividedTaskFromGeojsonResponse = await axios.post(url, dividedTaskFormData); const resp: OrganisationListModel = getGetDividedTaskFromGeojsonResponse.data; dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'divide_on_square', value: true }));