From 8d5c9ed4dd98df7a83a46f8afd3c93a95691f598 Mon Sep 17 00:00:00 2001 From: Vysakh Menon Date: Mon, 27 Sep 2021 09:21:38 -0700 Subject: [PATCH] 8908 fixed comparing time issue (#1187) --- api/namex/resources/payment/payment.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/namex/resources/payment/payment.py b/api/namex/resources/payment/payment.py index 8fb3fc8cd..8a98449f9 100644 --- a/api/namex/resources/payment/payment.py +++ b/api/namex/resources/payment/payment.py @@ -377,8 +377,14 @@ def post(self, nr_id, payment_action=NameRequestActions.CREATE.value): elif payment_action == PaymentDAO.PaymentActions.REAPPLY.value: # TODO: handle this (refund payment and prevent action?) + + # the `nr_model.expirationDate` is been set from nro with timezone info + # and `datetime.utcnow()` does not return with timezone info `+00:00` + # replacing timezone info to None in `nr_model.expirationDate` to avoid + # this error: `can't compare offset-naive and offset-aware datetimes` if nr_model.stateCd != State.APPROVED \ - and nr_model.expirationDate + timedelta(hours=NAME_REQUEST_EXTENSION_PAD_HOURS) < datetime.utcnow(): + and nr_model.expirationDate.replace(tzinfo=None) + \ + timedelta(hours=NAME_REQUEST_EXTENSION_PAD_HOURS) < datetime.utcnow(): msg = f'Extend NR for payment.id={payment.id} nr_model.state{nr_model.stateCd}, nr_model.expires:{nr_model.expirationDate}' current_app.logger.debug(msg)