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 import/export bug when sha384 or sha512 are null #1054

Merged
merged 1 commit into from
Dec 10, 2020
Merged
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/7836.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Pulp import/export bug that occurs when sha384 or sha512 is not in ``ALLOWED_CONTENT_CHECKSUMS``.
18 changes: 18 additions & 0 deletions pulpcore/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ContentArtifact,
)
from pulpcore.app.models.repository import Repository
from pulpcore.constants import ALL_KNOWN_CONTENT_CHECKSUMS
from pulpcore.plugin.importexport import QueryModelResource


Expand All @@ -19,6 +20,23 @@
# repo-version-specific.
#
class ArtifactResource(QueryModelResource):
"""Resource for import/export of artifacts."""

def before_import_row(self, row, **kwargs):
"""
Sets digests to None if they are blank strings.

Args:
row (tablib.Dataset row): incoming import-row representing a single Variant.
kwargs: args passed along from the import() call.

"""
# the export converts None to blank strings but sha384 and sha512 have unique constraints
# that get triggered if they are blank. convert checksums back into None if they are blank.
for checksum in ALL_KNOWN_CONTENT_CHECKSUMS:
if row[checksum] == "":
row[checksum] = None

class Meta:
model = Artifact
exclude = (
Expand Down