Skip to content

Commit

Permalink
Keep polling if the files are all uploaded but the status hasn't chan…
Browse files Browse the repository at this point in the history
…ged yet
  • Loading branch information
rebkwok committed Feb 14, 2025
1 parent dc15387 commit f1e3826
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion airlock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def output_files(self) -> dict[UrlPath, RequestFile]:
if rfile.filetype == RequestFileType.OUTPUT
}

def uploaded_files_count(self):
def uploaded_files_count(self) -> int:
if self.status not in [RequestStatus.APPROVED, RequestStatus.RELEASED]:
return 0
return sum(1 for rfile in self.output_files().values() if rfile.uploaded)
Expand Down Expand Up @@ -927,6 +927,9 @@ def upload_in_progress(self) -> bool:
rf.upload_in_progress() for rf in self.output_files().values()
)

def all_files_uploaded(self) -> bool:
return self.uploaded_files_count() == len(self.output_files())

def is_final(self):
return self.status_owner() == RequestStatusOwner.SYSTEM

Expand Down
5 changes: 4 additions & 1 deletion airlock/views/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,10 @@ def uploaded_files_count(request, request_id):
overview page.
"""
release_request = get_release_request_or_raise(request.user, request_id)
if release_request.upload_in_progress():
if release_request.upload_in_progress() or (
release_request.status == RequestStatus.APPROVED
and release_request.all_files_uploaded()
):
return TemplateResponse(
request,
"file_browser/_includes/uploaded_files_count.html",
Expand Down
11 changes: 9 additions & 2 deletions tests/functional/test_request_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,18 @@ def assert_still_uploading(uploaded_count):
release_files_button.click()
assert_still_uploading(2)

# complete the upload and release
# complete the upload
bll.register_file_upload(release_request, UrlPath("file3.txt"), output_checker)

# test for the race condition where the upload has been completed but the
# status hasn't yet been updated; in this case we want to continue to poll
# until the status has change to RELEASED
assert_still_uploading(3)

# Now update the status to released
bll.set_status(release_request, RequestStatus.RELEASED, output_checker)

# 3 files uploaded; request is no longer uploading so page has refreshed and no
# all files uploaded AND status updated; page has refreshed and no
# htmx attributes on the parent element anymore
# the release files button is not visible because the release is now complete
expect(uploaded_files_count_el).to_contain_text("3")
Expand Down

0 comments on commit f1e3826

Please sign in to comment.