Skip to content

Commit

Permalink
Fix is_highest logic on resyncs (#1548)
Browse files Browse the repository at this point in the history
fixes: #1547
(cherry picked from commit 6f7f087)
  • Loading branch information
gerrod3 authored and mdellweg committed Sep 25, 2024
1 parent 86e6182 commit 5fd8f4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/1547.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a sporadic sync error when re-syncing a repository with new collection versions.
11 changes: 9 additions & 2 deletions pulp_ansible/app/tasks/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ def _update_highest_version(collection_version, save=False):
If this version is the first version in collection, is_highest is set to True.
If this version is greater than the highest version in collection, set is_highest
equals False on the last highest version and True on this version.
Otherwise does nothing.
Otherwise does nothing. The collection version is updated to the database if `save=True`,
otherwise only the `is_highest` field is updated on the instance. This is an optimization
to prevent double saving when this method is called during syncs and uploads.
"""

def is_new_highest(new, old):
Expand All @@ -444,7 +446,7 @@ def is_new_highest(new, old):
collection_version.save(update_fields=["is_highest"])
return

# compute highest from the whole list ...
# previous highest must have been removed, re-compute highest from the whole list ...
highest = None
for cv in collection_version.collection.versions.all():
sv = Version(cv.version)
Expand All @@ -458,6 +460,11 @@ def is_new_highest(new, old):

# exit if the new CV is not higher
if not is_new_highest(Version(collection_version.version), Version(last_highest.version)):
# ensure that this collection_version doesn't have is_highest improperly set
if collection_version.is_highest:
collection_version.is_highest = False
if save:
collection_version.save(update_fields=["is_highest"])
return

last_highest.is_highest = False
Expand Down

0 comments on commit 5fd8f4e

Please sign in to comment.