Skip to content

Commit

Permalink
Fix errors when database is unpopulated (#234) (#233)
Browse files Browse the repository at this point in the history
Fixed errors that would result when the database was unpopulated.
Previously the "AIPs" and "Reports" pages would result in an "Internal
Server Error".
  • Loading branch information
mcantelon committed Dec 28, 2023
1 parent d5d7c19 commit 7c4eea8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions AIPscan/Reporter/database_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-


def get_possible_storage_locations(storage_service):
"""Return list of Storage Locations if storage service provided."""
if storage_service is None:
return []

return storage_service.storage_locations
11 changes: 8 additions & 3 deletions AIPscan/Reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
request_params,
sort_puids,
)
from AIPscan.Reporter.database_helpers import get_possible_storage_locations
from AIPscan.Reporter.helpers import (
calculate_paging_window,
get_premis_xml_lines,
Expand Down Expand Up @@ -83,7 +84,11 @@ def get_aip_pager(page, per_page, storage_service, storage_location):
except ValueError:
page = 1

pager = AIP.query.filter_by(storage_service_id=storage_service.id).paginate(
storage_service_id = None
if storage_service is not None:
storage_service_id = storage_service.id

pager = AIP.query.filter_by(storage_service_id=storage_service_id).paginate(
page=page, per_page=per_page, error_out=False
)

Expand Down Expand Up @@ -133,7 +138,7 @@ def view_aips():
storage_services=StorageService.query.all(),
storage_service=storage_service,
storage_locations=storage_locations_with_aips(
storage_service.storage_locations
get_possible_storage_locations(storage_service)
),
storage_location=storage_location,
pager=pager,
Expand Down Expand Up @@ -300,7 +305,7 @@ def reports():
storage_services=StorageService.query.all(),
storage_location=storage_location,
storage_locations=storage_locations_with_aips(
storage_service.storage_locations
get_possible_storage_locations(storage_service)
),
original_file_formats=original_file_formats,
preservation_file_formats=preservation_file_formats,
Expand Down

0 comments on commit 7c4eea8

Please sign in to comment.