Skip to content

Commit

Permalink
fix: update db relations for generating submissions (#1179)
Browse files Browse the repository at this point in the history
* fix: update submission in s3

* Fix: error handling in s3

* removed optional from get_obj_from_bucket

---------

Co-authored-by: sujanadh <sujanadh07@gmail.com>
  • Loading branch information
Sujanadh and sujanadh authored Feb 8, 2024
1 parent 9cbc5b9 commit 1b18dc2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class DbTaskHistory(Base):
invalidation_history = relationship(
DbTaskInvalidationHistory, lazy="dynamic", cascade="all"
)
actioned_by = relationship(DbUser)
actioned_by = relationship(DbUser, overlaps="task_history_user,user")
task_mapping_issues = relationship(DbTaskMappingIssue, cascade="all")

__table_args__ = (
Expand Down
1 change: 1 addition & 0 deletions src/backend/app/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def get_obj_from_bucket(bucket_name: str, s3_path: str) -> BytesIO:
response = client.get_object(bucket_name, s3_path)
return BytesIO(response.read())
except Exception as e:
log.warning(f"Failed attempted download from S3 path: {s3_path}")
raise ValueError(str(e)) from e
finally:
if response:
Expand Down
6 changes: 3 additions & 3 deletions src/backend/app/submissions/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,9 @@ def update_submission_in_s3(
metadata_s3_path = f"/{s3_project_path}/submissions.meta.json"
try:
# Get the last submission date from the metadata
file = get_obj_from_bucket(settings.S3_BUCKET_NAME, metadata_s3_path)
zip_file_last_submission = (json.loads(file.getvalue()))["last_submission"]
data = get_obj_from_bucket(settings.S3_BUCKET_NAME, metadata_s3_path)

zip_file_last_submission = (json.loads(data.getvalue()))["last_submission"]
if last_submission <= zip_file_last_submission:
# Update background task status to COMPLETED
update_bg_task_sync = async_to_sync(
Expand All @@ -369,7 +370,6 @@ def update_submission_in_s3(

except Exception as e:
log.warning(str(e))
pass

# Zip file is outdated, regenerate
metadata = {
Expand Down

0 comments on commit 1b18dc2

Please sign in to comment.