Hi,

I have a very strange problem that I don't know why it happens.
I'm creating a REST API service that wraps another REST API payment 
service, let's call the other services XPAY. It has various payment options 
(Card, eWallet, Kiosk, and Cash). The steps required to use the services 
(to make a transaction)

1. authentication 2. order registration 3. payment key 4. prepare frontend 
based on payment type 5. Callback URL 6. Redirect URL

and each step depends on its predecessor. The first 4 steps are performed 
through HTTP Requests that I issue from my service. I store some of the 
information I receive in those steps in a Model called Transaction. 5th and 
6th steps are Callback endpoints that I create to receive further 
information about the status of the transaction that I started in the first 
4 steps.

My endpoints design is:

myservice/payment/card
myservice/payment/wallet
myservice/payment/kiosk
myservice/payment/cash

myservice/payment/callback-url
myservice/payment/redirect-url

These endpoints are wrappers for the payment methods available in XPAY's 
service that my frontend apps will use to provide those payment options for 
users.

I implemented the first 3 endpoints with no problem. inside those 
endpoints, I create a transaction object with a unique id and then update 
it from inside the *callback-url endpoint* after I receive the information 
from XPAY's service. Note that it takes some time between creating the 
Transaction object and saving it into the database from inside my endpoint, 
and updating it from inside the callback url endpoint.

The weird thing happens in the 4th endpoint `cash` endpoint. XPAY's service 
responds very quickly on my *callback-url endpoint* and when it gets to the 
updating step, I get *Transaction.DoesNotExist *Exception while getting the 
transaction object using Transaction.objects.get(id=id).

After some debugging time using ipdb I found that the instance has already 
been saved to the database! and I can retrieve it with its id. but when I 
let it run ordinarily the saving operation doesn't finish until that time 
(I got to know that using some print() statements), which is very strange, 
it's impossible that my laptop is that slow! 

Solutions I tried:
1. atomic transaction
2. time.sleep some time after making the request and saving the transaction 
object to the db
3. time.sleep in the callback-url before getting the transaction from DB

I checked any possible logic error related to it and there's nothing 
illogical.

the issue is related to Postgres and how it operates, and also with 
Django's ORM. I don't know.

Main technologies I use:
Django 2.2
Postgres Docker container
DRF

I hope someone gives me an insight into why this is happening and how to 
work around it.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e43be322-bab9-4162-9fbc-05c6c9b95c94%40googlegroups.com.

Reply via email to