From 1fcef255a6434a99746bff68e1f9467e80f1ed33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 19 Jun 2026 12:43:46 +0200 Subject: [PATCH] Fix convert_prices storing exchange rate as string 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 --- games/tasks.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/games/tasks.py b/games/tasks.py index e4920ff..bff204f 100644 --- a/games/tasks.py +++ b/games/tasks.py @@ -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, )