gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] 06/12: Addressing #5543.


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 06/12: Addressing #5543.
Date: Fri, 29 Mar 2019 18:08:25 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

commit 5bc40f6cd56b5b3731d705409f31ef6711c8aa25
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Feb 8 16:22:53 2019 +0100

    Addressing #5543.
---
 talerbank/app/models.py | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index 0e9cc47..211ee49 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -28,6 +28,16 @@ from django.core.exceptions import \
     ObjectDoesNotExist
 from .amount import Amount, BadFormatAmount, CurrencyMismatch
 
+class InvalidAmount(Amount):
+    def __init__(self, currency):
+        super(InvalidAmount, self).__init__(currency, value=float('nan'), 
fraction=float('nan'))
+
+    def stringify(self):
+        return "Invalid Amount, please report"
+    def dump(self):
+        return "Invalid Amount, please report"
+
+class AmountField(models.Field):
 
 ##
 # Helper function that instantiates a zero-valued @a Amount
@@ -75,7 +85,22 @@ class AmountField(models.Field):
         del args # pacify PEP checkers
         if value is None:
             return Amount.parse(settings.TALER_CURRENCY)
-        return Amount.parse(value)
+        try:
+            return Amount.parse(value)
+        except NumberTooBig:
+            # Keep the currency right to avoid causing
+            # exceptions if some operation is attempted
+            # against this invalid amount.  NOTE that the
+            # value is defined as NaN, so no actual/useful
+            # amount will ever be generated using this one.
+            # And more, the NaN value will make it easier
+            # to scan the database to find these faulty
+            # amounts.
+            # We also decide to not raise exception here
+            # because they would propagate in too many places
+            # in the code, and it would be too verbose to
+            # just try-cactch any possible exception situation.
+            return InvalidAmount(settings.TALER_CURRENCY)
 
 
     ##

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]