Fix convert_prices storing exchange rate as string
Django CI/CD / test (push) Successful in 4m4s
Staging deployment / deploy (push) Failing after 31s
Staging deployment / comment (push) Has been skipped
Staging deployment / teardown (push) Has been skipped
Django CI/CD / build-and-push (push) Has been skipped

floatformat() returns a str; saving that to ExchangeRate.rate (FloatField)
via create() leaves the Python instance attribute as a str. Reading it back
on the same instance (rate = exchange_rate.rate) then caused
`purchase.price * rate` to fail with "can't multiply sequence by non-int
of type 'float'".

Fix: pass the raw float from the API directly to ExchangeRate.objects.create.
Also replace floatformat(..., 0) on the converted price with round(..., 2)
to keep a numeric type throughout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 12:43:46 +02:00
parent 97fff21b28
commit 1fcef255a6
+2 -4
View File
@@ -2,8 +2,6 @@ import logging
import requests
from django.db import models
from django.template.defaultfilters import floatformat
from games.models import ExchangeRate, Purchase
logger = logging.getLogger("games")
@@ -38,7 +36,7 @@ def _get_exchange_rate(currency_from, currency_to, year):
currency_from=currency_from,
currency_to=currency_to,
year=year,
rate=floatformat(rate, 2),
rate=rate,
)
rate = exchange_rate.rate
else:
@@ -84,7 +82,7 @@ def convert_prices():
if rate:
_save_converted_price(
purchase,
floatformat(purchase.price * rate, 0),
round(purchase.price * rate, 2),
needs_update,
)