diff --git a/python/spacewalk/server/importlib/backend.py b/python/spacewalk/server/importlib/backend.py index 644343f979e4..aad247294904 100644 --- a/python/spacewalk/server/importlib/backend.py +++ b/python/spacewalk/server/importlib/backend.py @@ -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 diff --git a/python/spacewalk/server/importlib/backendLib.py b/python/spacewalk/server/importlib/backendLib.py index 535e82cca437..00ffe62a22d0 100644 --- a/python/spacewalk/server/importlib/backendLib.py +++ b/python/spacewalk/server/importlib/backendLib.py @@ -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 diff --git a/python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values b/python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values new file mode 100644 index 000000000000..5ed448af24d4 --- /dev/null +++ b/python/spacewalk/spacewalk-backend.changes.mczernek.round-int-values @@ -0,0 +1 @@ +- Handle package metadata that contains float value instead of an integer (GH#9613)