Request result update only if I change even one character... Strange... :s

10 views
Skip to first unread message

Sébastien Denooz

unread,
Jan 8, 2022, 10:05:06 AM1/8/22
to Django users
Hello to all of you,

I have a very strange behavior that I do not understand and that I will try to explain here:

Global situation: School management website.

Expected comportment: User show student amout: 10. User Add 5, return to app, pull down to refresh and see 15.

Actual comportment: User show student amout: 10. User Add 5, return to app, pull down to refresh and see 10.

Fix: I change only on char in my code (even a space, a letter, a tab or anything else), the manage.py runserver reload, i pull down to refresh and see 15.

If i put the code of the function that calculate the total amount direct in the method user in the request, all is good. :/

Totaly incomprehensible :s

Details:
- I have 2 applications: One manages students, another manages payments for them.
- In my payment model, I have this function :
class Payment(SoftDeleteObject, models.Model):
    amount = models.FloatField()
    ...

    @staticmethod
    def get_total_payments(wallet_reference=False, date=timezone.datetime.now()):
        """"
        Get total payment from wallet reference and from a date
        @param wallet_reference:
        @param date:
        @return:
        """
        payments = Payment.objects.filter(
                Q(wallet_reference=wallet_reference),
                Q(payment_date__lte=date),
                Q(status=PAYMENT_STATUS['SUCCEEDED'])
        )
        total_payment = 0
        for payment in payments:
                total_payment += payment.amount
        return total_payment

- In my payment application, I use this function when I make a request to find the total available, the total consumed, etc... like this:

class ListStudentPayment(generics.GenericAPIView):

    def get(self, *args, **kwargs):
        today = timezone.now().date()
        student = Student.objects.get(pk=kwargs['student_id'])
       .... 
        total_payment = Payment.get_total_payments(student.wallet_reference)

- This function is called right after a stripe payment, to refresh my student's balance in the application.

Do you have an explaination ?

Thanks.

Reply all
Reply to author
Forward
0 new messages