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 8529843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:07:16+00:00 2026-06-11T09:07:16+00:00

I’m making a Pyramid app using SQLAlchemy-0.7.8. I’m using 64bit Python3.2. The question is,

  • 0

I’m making a Pyramid app using SQLAlchemy-0.7.8. I’m using 64bit Python3.2.

The question is, why does the following function not commit anything to the database?

def create_card(sText,sCard):
    """
    create a wildcard instance if all is well (ie,sCard match in sText)
    return 
        oCard, dCard
    otherwise return False,False
    """
    oMatch = re.search(sCard,sText)
    if oMatch:
        oCard = WildCard()
        #set up some stuff about the WildCard

        DBSession.add(oCard)
        DBSession.flush()
        dCard = {
                    'id'            : oCard.id,
                    'span'          : oMatch.span(),
                    'card'          : oCard.card_string,
                            }
        return oCard,dCard
    return False,False  

I import DBSession form another script. it is defined as follows:

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))

Here’s some background info:

The app I’m making is to be used to characterize large blocks of HTML through use of regular expressions. If the app gets stuck and thinks there should be a wilcard match for a piece of text then the user is given a little form to fill in. Once the form is committed create_card is called. If the wildcard is matched against the string then a WildCard instance is created.

The WildCard class is nothing special, it just stores a string and a few integers. If I print out dCard it looks like the WildCard was sucessfully committed because it has an integer id. If I don’t call flush on the database session then dCard[‘id’] is None.

the id field looks like:

id = Column(Integer,Sequence('wild_seq'), primary_key=True)

The add and flush lines cause the following console output:

2012-09-16 12:30:34,845 INFO  [sqlalchemy.engine.base.Engine][Dummy-2] INSERT INTO wildcard_wildcards (card_string, range_id, brand_id, category_id, group_cat_map_id, heading_group_id, heading_to_grp_map_id, heading_id, value_map_id, igneore_match) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2012-09-16 12:30:34,845 INFO  [sqlalchemy.engine.base.Engine][Dummy-2] ('sCard contents', None, None, None, None, None, None, None, None, 0)

So up until this point everything is behaving pretty as is expected.

Here’s the problem:
Even though the WildCard instance looks like it has been committed to the database, and no Exceptions are raised, direct examination of the database shows that no changes are made.

replacing flush() with commit() raises the following exception:

AssertionError: Transaction must be committed using the transaction manager
  • 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-06-11T09:07:18+00:00Added an answer on June 11, 2026 at 9:07 am

    You need to commit your transaction.

    You can do this explicitly (by calling DBSession.commit() or by using the pyramid_tm middleware; the latter commits transactions automatically on successful responses (with a 2xx HTTP response).

    The latter only commits transactions for SQLAlchemy if you use the ZopeTransactionExtension extension with your session maker:

    from zope.sqlalchemy import ZopeTransactionExtension
    
    DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
    

    If you are already using the ZopeTransactionExtension and want to explicitly commit your transactions, you need to use the transaction package:
    import transaction

    transaction.commit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.