-
Notifications
You must be signed in to change notification settings - Fork 195
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
Enable packages metadata to be float when int is expected #9726
base: master
Are you sure you want to change the base?
Conversation
946688a
to
974e9a8
Compare
974e9a8
to
f24c4dc
Compare
value = value[: datatype.limit] | ||
# ignore incomplete characters created after truncating | ||
return value | ||
return _sanitize_dbstring(value, datatype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this into a separate function so that sonarcloud won't fail with method complexity being too high.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we use classes, but then don't do this with the classes. Would be too big to change that here, but it's something we could think about changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any examples we can use for testing this change?
@@ -0,0 +1 @@ | |||
- Handle pkg metadata containing float instead of an int (GH#9613) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using "GH" without any project/repo in changelogs? If we don't like gh#uyuni-project/uyuni#9613
, maybe we could request to add uyuni#9613
to known trackers in OBS?
value = value[: datatype.limit] | ||
# ignore incomplete characters created after truncating | ||
return value | ||
return _sanitize_dbstring(value, datatype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we use classes, but then don't do this with the classes. Would be too big to change that here, but it's something we could think about changing.
@agraul for testing, see [0]. I personally tested it with the To not sync the whole repo, I created a local deb repo (using the [0] http://archive.raspberrypi.org/debian/dists/bookworm/main/binary-arm64/Packages |
Thanks for the pointer, I'll try to sync this to see if we can solve the issue higher up in the stack. Just to have a second approach we can compare to this one. |
The alternative that immediately came to my mind was to fix this at the outside layer instead of deep down close to the DB insertion. The downside is that this approach only works for known keys, instead of anything. But casting anything to float then int is maybe not needed either. python/spacewalk/server/importlib/debPackage.py | 5 +++++
modified python/spacewalk/server/importlib/debPackage.py
@@ -59,6 +59,11 @@ class debBinaryPackage(headerSource.rpmBinaryPackage):
value = header[field]
if key == "build_time" and isinstance(value, int):
value = gmtime(value) # unix timestamp
+ elif key == "payload_size" and value:
+ # Payload size / Installed-Size is an int, but some packages have
+ # bad metadata (float). Since Installed-Size is an estimation, truncating to int is ok
+ # https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size
+ value = int(float(value))
elif value == []:
value = None
elif value: I'm not sure why we currently keep every value as a string until it hits the DB and only casts it to the expected DB type. Maybe your approach fits better with the current approach. |
What does this PR change?
When we process package metadata, packages can mistakenly have float where we expect integer, for example
Installed Size
,Size
, etc.Though this is technically an invalid package, Uyuni can round such values to integer instead of throwing an exception.
In this PR, if a package contains a float value in metadata where we expect integer, we first round the value to the nearest integer.
In case where such value is neither float nor int, I improve the error that is displayed to the user.
Documentation
Links
Issue(s): #9613
Port(s): TODO
Changelogs
Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository
If you don't need a changelog check, please mark this checkbox:
If you uncheck the checkbox after the PR is created, you will need to re-run
changelog_test
(see below)Re-run a test
If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run:
Before you merge
Check How to branch and merge properly!