launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #32128
[Merge] ~lgp171188/launchpad:fix-karmacache-updater-types-issue-postgres-14 into launchpad:master
Guruprasad has proposed merging ~lgp171188/launchpad:fix-karmacache-updater-types-issue-postgres-14 into launchpad:master.
Commit message:
Handle Decimal values in karma calculations with Postgres 14
As the type returned by Postgres changed from a float in Postgres 12 to
a Decimal in Postgres 14, we need to handle it gracefully.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lgp171188/launchpad/+git/launchpad/+merge/479915
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/launchpad:fix-karmacache-updater-types-issue-postgres-14 into launchpad:master.
diff --git a/cronscripts/foaf-update-karma-cache.py b/cronscripts/foaf-update-karma-cache.py
index 844a518..a569461 100755
--- a/cronscripts/foaf-update-karma-cache.py
+++ b/cronscripts/foaf-update-karma-cache.py
@@ -5,6 +5,8 @@
import _pythonpath # noqa: F401
+from decimal import Decimal
+
from zope.component import getUtility
from lp.app.errors import NotFoundError
@@ -284,7 +286,15 @@ class KarmaCacheUpdater(LaunchpadCronScript):
at C_add_summed_totals to see how the summed entries are generated.
"""
(person_id, category_id, product_id, distribution_id, points) = entry
- points *= scaling[category_id] # Scaled. wow.
+ # XXX lgp171188 2025-01-22 In Postgres 14, the points column gets
+ # returned as a Decimal instead of a float as before. So convert the
+ # operands to Decimal to perform the arithmetic in that case, and then
+ # convert back to a float so that there is no precision lost during the
+ # operation, just at the time of conversion. This can be removed once
+ # we have upgraded to a Postgres version >= 14.
+ if isinstance(points, Decimal):
+ scaling[category_id] = Decimal(scaling[category_id])
+ points = float(points * scaling[category_id]) # Scaled. wow.
self.logger.debug(
"Setting person_id=%d, category_id=%d, points=%d"
% (person_id, category_id, points)