Home > Blockchain >  Django database storage issue
Django database storage issue

Time:01-07

So I am running a particular code block in threads(5), and in the code been executed by the threads data are been saved to the database. e.g.

link = AccountLinkModel.objects.create(account=account)

if I print the value of "link" object and any field from the AccountLinkModel model, they print successfully, which means the data was created, but eventually, the record of some was not found in the Database, only few were recorded in the database.

Any advice on what might cause this?

CodePudding user response:

Maybe try to run it with only 1 thread to see if the problem still occurs, if not you might have a race condition in your code where you are not properly locking a shared ressource of your threads.

CodePudding user response:

if I print the value of "link" object and any field from the AccountLinkModel model, they print successfully, which means the data was created.

If the create function is wraped by a transaction block like

with transaction.atomic:
    link = AccountLinkModel.objects.create(account=account)
   ...other db stuff

Then the object is not persistet at the database after the create funktion was called. If you print after the create call, then that are just the python attributes from the ram.

  •  Tags:  
  • Related