Home > Software engineering >  Django project doesnt insert into Oracle table
Django project doesnt insert into Oracle table

Time:11-02

I'm building a integration app that consumes data from a API and save the sensitive information into a table inside a oracle database. My models succesfully migrated and created the tables and I was able to also succesfully consume and filter the data I need from the API, so I proceeded to use objects.update_or_create to populate my table with the data, initially it worked fine and inserted the information normally until it got stuck and stoped the querys. After that I droped the tables and started the migration process anew, and also changed my method to objects.create with .save(force_insert=True) to brute force the process and insert the data inside the table, but the problem persisted and I'm kinda lost not knowing what is wrong mainly because it doesnt raise any error nor exception and just remains stuck into the block.

for item in value_list['itens']:
    print(item)
    i = Item.objects.using('adm_int').create(
        nature=item['nature'],
        nr_doc=item['nr_doc'],
        name=item['name'],
        value=item['value'],
        type_op=item['type'],
        description=item['history']['description'],
    )
    i.save(force_insert=True)

Inside the response from the API there'll be N number of itens, so I need to insert the data from each item into the table. When it begins the loop it doesnt insert the data and stops there.

CodePudding user response:

I was able to solve this. I added a sleep at the end of my loop so that django would wait for the database to end the insert before running the loop one more time. What I think was happening is that the db was not able to keep up with the update of the app and was blocking the insert while holding the session up.

  • Related