Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/152.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unexpected errors during PD Excel doc file uploads now log the exception. Now skips over unexpected "cache" worksheets in the Excel doc when processing uploaded files.
7 changes: 7 additions & 0 deletions ckanext/recombinant/read_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


def read_excel(f: Union[str, FlaskFileStorage, FieldStorage],
expected_sheet_names: List[str],
file_contents: Optional[str] = None) -> Iterator[Any]:
"""
Return a generator that opens the excel file f (name or file object)
Expand All @@ -35,6 +36,12 @@ def read_excel(f: Union[str, FlaskFileStorage, FieldStorage],
for sheetname in wb.sheetnames:
if sheetname == 'reference':
return
if sheetname not in expected_sheet_names:
# NOTE: some Excel extensions and Macros create fully hidden
# worksheets that act as a sort of database/index cache
# for other sheets or external services such as Geo Services.
# We want to skip these as those sheets will not have what we need.
continue
# type_ignore_reason: incomplete typing
sheet: Worksheet = wb[sheetname]
rowiter = sheet.rows
Expand Down
7 changes: 5 additions & 2 deletions ckanext/recombinant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ def _process_upload_file(lc: LocalCKAN,
(resource['name'], resource['id'])
for resource in dataset['resources'])

upload_data = read_excel(upload_file)
# type_ignore_reason: incomplete typing
upload_data = read_excel(upload_file, expected_sheet_names.keys()) # type: ignore
total_records = 0
# type_ignore_reason: incomplete typing
backend: DatastorePostgresqlBackend = DatastoreBackend.\
Expand All @@ -765,7 +766,9 @@ def _process_upload_file(lc: LocalCKAN,
break
except BadExcelData as e:
raise e
except Exception:
except Exception as e:
log.info('Unexpected error while uploading Recombinant file:')
log.info(e)
# unfortunately this can fail in all sorts of ways
if asbool(config.get('debug', False)):
# on debug we want the real error
Expand Down