[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
- [GNUnet-SVN] [taler-bank] branch master updated (a3e7f9d -> 8c2d25b), gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 02/12: Minor change for #5542., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 04/12: providing the 'hint' field to those exeptions missing it., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 01/12: Hot-addressing #5542., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 07/12: Addressing #5543., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 08/12: Addressing #5543., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 05/12: typo, gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 06/12: Addressing #5543.,
gnunet <=
- [GNUnet-SVN] [taler-bank] 03/12: Handling new exeption within the middleware., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 12/12: #5546, gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 10/12: syntax, gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 09/12: 5543. Let Jinja render abnormal balances., gnunet, 2019/03/29
- [GNUnet-SVN] [taler-bank] 11/12: syntax, gnunet, 2019/03/29