Skip to content

Commit

Permalink
Enable packages metadata to be float when int is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
m-czernek committed Feb 4, 2025
1 parent aa3f3cb commit 946688a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions python/spacewalk/server/importlib/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3360,16 +3360,21 @@ def _buildDatabaseValue(row, fieldsHash):
def _buildExternalValue(dict, entry, tableObj):
# updates dict with values from entry
# entry is a hash-like object (non-db)
for f, datatype in list(tableObj.getFields().items()):
if f in dict:
for field, datatype in list(tableObj.getFields().items()):
if field in dict:
# initialized somewhere else
continue
# Get the attribute's name
attr = tableObj.getObjectAttribute(f)
attr = tableObj.getObjectAttribute(field)
# Sanitize the value according to its datatype
if attr not in entry:
entry[attr] = None
dict[f] = sanitizeValue(entry[attr], datatype)
try:
dict[field] = sanitizeValue(entry[attr], datatype)
except ValueError as e:
raise ValueError(
f"Cannot sanitize value from {field}={entry[attr]} to {type(datatype)}"
) from e


# pylint: disable-next=invalid-name
Expand Down
5 changes: 4 additions & 1 deletion python/spacewalk/server/importlib/backendLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,10 @@ def sanitizeValue(value, datatype):
if isinstance(datatype, DBdate):
return str(value)[:10]
if isinstance(datatype, DBint):
return int(value)
try:
return float(int(value))
except ValueError as e:
raise ValueError(f"Cannot convert {value} to int") from e
return value


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Handle package metadata that contains float value instead of an integer (GH#9613)

Check failure on line 1 in python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values

View workflow job for this annotation

GitHub Actions / Changelog tests

Line exceeds 67 characters in file python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values#L1

Check warning on line 1 in python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values

View workflow job for this annotation

GitHub Actions / Changelog tests

Possibly a mistyped tracker in file python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values#L1

Check failure on line 1 in python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values

View workflow job for this annotation

GitHub Actions / Changelog tests

Line exceeds 67 characters in file python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values#L1

Check warning on line 1 in python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values

View workflow job for this annotation

GitHub Actions / Changelog tests

Possibly a mistyped tracker in file python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values#L1

0 comments on commit 946688a

Please sign in to comment.