Skip to content

Commit 0e09ec4

Browse files
authored
Fix to exception handling for XLSX (#14138)
1 parent a9ade43 commit 0e09ec4

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

geonode/upload/handlers/xlsx/handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,13 @@ def pre_processing(self, files, execution_id, **kwargs):
236236
# Note: rows_gen continues from the row after the headers
237237
self._convert_to_csv(headers, rows_gen, output_file)
238238

239+
except InvalidInputFileException as e:
240+
logger.exception(f"XLSX Pre-processing failed: {e}")
241+
raise
242+
239243
except Exception as e:
240-
logger.exception("XLSX Pre-processing failed")
241-
raise InvalidInputFileException(detail=f"Failed to securely parse Excel: {str(e)}")
244+
logger.exception(f"XLSX Pre-processing failed: {e}")
245+
raise InvalidInputFileException(detail="Failed to parse Excel.")
242246

243247
# update the file path in the payload
244248
_data["files"]["base_file"] = output_file

geonode/upload/handlers/xlsx/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def test_pre_processing_fails_on_missing_lat(self, mock_get_exec):
8080
):
8181
with self.assertRaises(InvalidInputFileException) as context:
8282
self.handler.pre_processing(files, exec_id)
83-
8483
self.assertIn("geometry headers", str(context.exception))
8584

8685
@patch("geonode.upload.orchestrator.orchestrator.get_execution_object")
@@ -158,7 +157,7 @@ def test_security_billion_laughs_protection(self):
158157
with self.assertRaises(InvalidInputFileException) as context:
159158
self.handler.pre_processing(files, exec_id)
160159

161-
self.assertIn("Failed to securely parse Excel", str(context.exception))
160+
self.assertIn("Failed to parse Excel", str(context.exception))
162161
finally:
163162
if os.path.exists(malicious_path):
164163
os.remove(malicious_path)

0 commit comments

Comments
 (0)