Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ansible collections import error #1987

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1986.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Find and set the current highest collection version in the database to False before importing the new highest version to prevent conflict.
13 changes: 13 additions & 0 deletions pulp_ansible/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ def before_import_row(self, row, **kwargs):
col = Collection.objects.get(name=row["name"], namespace=row["namespace"])
row["collection"] = str(col.pk)

def get_instance(self, instance_loader, row):
"""
This fixes https://github.com/pulp/pulp_ansible/issues/1986
Find and set the current highest version to False before importing the new highest version.
"""
instance = super().get_instance(instance_loader, row)
if not instance and row["is_highest"] == "1":
CollectionVersion.objects.filter(
collection_id=row["collection"], is_highest=True
).update(is_highest=False)

return instance
Comment on lines +124 to +130
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn it! is_highest really needs to go away.
Thank you for finding this.
I think however, we cannot be sure that when importing a highest collection version, that there is no higher one in the system already. Am I right, that you don't actually care about the is_highest flag? And this seems to fix the issue with the database constraint?
I guess we could also just lift the constraint, if we realize we want to accept inconsistent data here.


def set_up_queryset(self):
"""
:return: CollectionVersion content specific to a specified repo-version.
Expand Down
Loading