Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6251079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:32:49+00:00 2026-05-24T13:32:49+00:00

Setup: Python script A inserts data to a database every 15 minutes Python script

  • 0

Setup:

  • Python script A inserts data to a database every 15 minutes
  • Python script B queries a few of the latest entries from the database every few minutes

Both use Django’s ORM, run on the same machine and use a local MySQL database.

The Problem:
B fetches entries, except for the latest one, even though A saves it minutes before.

I suspected that A doesn’t close the transaction, thus B sees the database without the last entry. Indeed when examining the MySQL logs, I noticed the commit for each INSERT happens right before the next INSERT.

Even though it’s supposed to be redundant, I added @commit_on_success decorator to the A function that includes the save(), but it did not help.

How can I force Django (or MySQL?!) to commit right after the save()?

UPDATE:
I discovered that the commits DO happen – I was mislead to believe they don’t because MySQL’s General Query Log only has 1 sec resolution.
In light of this and other new information, I’ve reasked the question here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:32:50+00:00Added an answer on May 24, 2026 at 1:32 pm

    You can use the commit_manually decorator and call it whenever you want.

    Straight from the documentation:

    from django.db import transaction
    
    @transaction.commit_manually
    def viewfunc(request):
        ...
        # You can commit/rollback however and whenever you want
        transaction.commit()
        ...
    
        # But you've got to remember to do it yourself!
        try:
            ...
        except:
            transaction.rollback()
        else:
            transaction.commit()
    

    This answers the question you asked, though I wonder if there might be something else at work.

    NOTE: commit_manually was deprecated in 1.6 and removed in 1.8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a setup.py script for py2exe, generated an executable for my python GUI
Every Python developer is familiar with easy_install and setup tools. If I want to
I have a python script that connects to an external host, fetches some data,
I've created a python script that's intended to be used from the command line.
I'm trying to use a JPEG image in a QImage object from a Python
I am trying to use 'py2app' to generate a standalone application from some Python
I've setup an Amazon EC2 server. I have a Python script that is supposed
I'm trying to export a Selenium script to Python from the Selenium IDE. I
How can I persistently modify the Windows environment variables from a Python script? (it's
How do you set up IIS so that you can call python scripts from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.