Skip to content

Commit

Permalink
Fix is_highest logic on resyncs
Browse files Browse the repository at this point in the history
fixes: pulp#1547
  • Loading branch information
gerrod3 committed Aug 8, 2023
1 parent ae4598e commit 1334235
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 @@ -428,7 +428,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 @@ -447,7 +449,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 @@ -461,6 +463,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 1334235

Please sign in to comment.