Skip to content

Commit

Permalink
Fix a serialization issue
Browse files Browse the repository at this point in the history
Our data model allows null sum_types, but createrepo_c types don't
allow setting such values. It defaults to a value of 0, or "unknown"

Let's only print a checksum if we have a sensible value for both sum and
sum_type.

[noissue]
  • Loading branch information
dralley committed Jan 31, 2024
1 parent 07ddb43 commit 486fd7e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pulp_rpm/app/models/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class UpdateCollectionPackage(BaseModel):
Source filename
sum (Text):
Checksum
sum_type (Text):
sum_type (PositiveInteger):
Checksum type
version (Text):
Version
Expand Down Expand Up @@ -436,8 +436,7 @@ def createrepo_to_dict(cls, package):
or "",
PULP_UPDATE_COLLECTION_PACKAGE_ATTRS.SUM_TYPE: getattr(
package, CR_UPDATE_COLLECTION_PACKAGE_ATTRS.SUM_TYPE
)
or None,
),
PULP_UPDATE_COLLECTION_PACKAGE_ATTRS.VERSION: getattr(
package, CR_UPDATE_COLLECTION_PACKAGE_ATTRS.VERSION
)
Expand Down Expand Up @@ -466,7 +465,10 @@ def to_createrepo_c(self):
pkg.relogin_suggested = self.relogin_suggested
if self.restart_suggested:
pkg.restart_suggested = self.restart_suggested
if self.sum:
if self.sum and self.sum_type:
# Whether self.sum is None controls whether or not the <sum> tag will be serialized
# If self.sum_type is 0 the result will be createrepo_c printing "Unknown checksum",
# an invalid value, thus we don't want to set self.sum if this will happen.
pkg.sum = self.sum
pkg.sum_type = self.sum_type

Expand Down

0 comments on commit 486fd7e

Please sign in to comment.