From 2c0941e3041a5a7833099494b2d45b1306f60419 Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Thu, 12 Dec 2024 14:43:19 -0800 Subject: [PATCH] fix: Convert Decimal to int Decimal is not JSON serializable to fails to send message, convert to int before sending --- backend/api/services/TransactionMessageService.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/api/services/TransactionMessageService.py b/backend/api/services/TransactionMessageService.py index b131cf0b9..773e01701 100644 --- a/backend/api/services/TransactionMessageService.py +++ b/backend/api/services/TransactionMessageService.py @@ -1,4 +1,6 @@ import json +from decimal import Decimal + import pika from pika.exceptions import AMQPError from tfrs.settings import AMQP_CONNECTION_PARAMETERS @@ -13,8 +15,9 @@ class TransactionDeliveryFailure(Exception): class TransactionMessageService: @staticmethod def send_transaction_message( - tfrs_id: int, organization_id: int, compliance_units_amount: int + tfrs_id: int, organization_id: int, compliance_units_amount: Decimal ): + try: # Use existing AMQP connection parameters from settings parameters = AMQP_CONNECTION_PARAMETERS @@ -28,7 +31,7 @@ def send_transaction_message( message = { "tfrs_id": tfrs_id, "organization_id": organization_id, - "compliance_units_amount": compliance_units_amount, + "compliance_units_amount": int(compliance_units_amount.to_integral_value()), } # Publish the message to the queue