Skip to content

Commit

Permalink
Merge pull request #11904 from rtibbles/unique_removal_request
Browse files Browse the repository at this point in the history
Prevent unique constraint saving errors.
  • Loading branch information
bjester authored Feb 20, 2024
2 parents 96c528b + a4e4279 commit 0ca9ff1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions kolibri/core/content/utils/content_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,17 @@ def process_user_downloads_for_removal():
largest_user_download = user_downloads.order_by("-total_size").first()

# adding this opposite of the user download request allows us to detect this situation
user_download_removal = ContentRemovalRequest(
facility_id=largest_user_download.facility_id,
# this removal request will be processed on the next loop
ContentRemovalRequest.objects.update_or_create(
source_model=largest_user_download.source_model,
source_id=largest_user_download.source_id,
reason=ContentRequestReason.SyncInitiated,
status=ContentRequestStatus.Pending,
contentnode_id=largest_user_download.contentnode_id,
defaults=dict(
facility_id=largest_user_download.facility_id,
reason=ContentRequestReason.SyncInitiated,
status=ContentRequestStatus.Pending,
),
)
# this removal request will be processed on the next loop
user_download_removal.save()
logger.info(
"Added removal request for user download of {}".format(
largest_user_download.contentnode_id
Expand Down

0 comments on commit 0ca9ff1

Please sign in to comment.