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

  • SEARCH
  • Home
  • 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 4323880
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:03:32+00:00 2026-05-21T09:03:32+00:00

I read the chapter in the Django docs about the transaction management. From what

  • 0

I read the chapter in the Django docs about the transaction management. From what I understand, the transaction is started as soon as TransactionMiddleware is invoked. Then by using @commit_on_success, @commit_manually there is a possibility of controlling transaction ending.

My question: is there a possibility to control transaction beginning as well without getting rid of TransactionMiddleware altogether. My concern is that many parts of Django framework actually depend on TransactionMiddleware presence, so I don’t really want to break it. I’d like it to be used for all the views except for those that belong to the applications that I explicitly specify. Most of all I’d like to be able to control transactional behaviour for certain group of views totally – from the beginning until the end. What approach should I take? Are there any external apps, libraries to help me out? Are transactions created eagerly or lazily – as soon as the first database hit occurs?

  • 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-21T09:03:33+00:00Added an answer on May 21, 2026 at 9:03 am
    1. Transactions are created with first DB query.

    2. TransactionMiddleware applies something similar to commit_on_success to all your views. There’s no need to add this explicitly. commit_on_success is still useful for giving this behavior to specific functions you call from within a view.

    3. Nested transactions are supported.

    So, why do you need to control transaction start? If you want to rollback just part of changes, this should be done using nested transactions.

    Here’s common use case from my code:

    @transaction.commit_manually
    def purchase(request, ...):
        try:
          ... # change some data
          _purchase(request, *args, **kwargs) # process purchase optimistically
        except PurchaseError, ex: # My own exception class for errors we know about
          _log_purchase(request, ex) # Save error in DB
          messages.error(ex.human_message())
          transaction.commit() # Save log entries
        except:
          transaction.rollback()
          raise
        else:
          transaction.commit()
    
    @transaction.commit_on_success
    def _purchase(request, ...):
        ...  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read in Chapter 4 of the NHibernate docs that all of a
I just read the iOS Human Interface Guidelines . In the chapter about Alerts,
I'm taking the plunge into iPhone development after about two years working with django.
I've read chapter 7 in the 'Linux Device Drivers' (which can be found here)
I read a chapter in a book (Seven languages in Seven Weeks by Bruce
I am learning Hibernate and just read the chapter 7.2.3 Adding columns to join
I've got this function, which I modified from material in chapter 1 of the
Possible Duplicate: return statement vs exit() in main() I've just read the first chapter
I have read Marcus Zarra's chapter on multithreading in his Core Data book and
I know all the classical SEO articles have a chapter about how important it

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.