I'm not familiar with that codebase (though I know, its the openstack base, maybe I should be), so it's hard to say. The begin() method on Session is usually not used because the docs recommend the Session remain in "autocommit=False" mode, so I'd need to better understand the overarching patterns of Session use here. Overall, there should be a consistent usage pattern for Session here - there shouldn't be any ad-hoc "let's use begin() here, but not there" type of thing. Using the session in "autocommit" mode without any transaction is strongly discouraged as it leads to confusion like this.
Anyway, the original question would be easier to answer if you'd send me the stack trace illustrating this TypeError you refer to. On Jan 8, 2013, at 5:40 AM, Gurjar, Unmesh wrote: > Hi, > > I wrote (the attached) script to reproduce the issue, however, it seems to be > working fine (i.e it returns the right exception). After a detailed check of > my application source > (https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/api.py#L1981 > ), I found that adding a session.begin( ) call before calling the method > save( ) (which internally does a session.add( ) and session.flush( )), > resolves the issue. Does this fix look correct? > > > Thanks & Regards, > Unmesh Gurjar | Lead Engineer | NTT DATA Global Technology Services Private > Limited | w. +91.20.6604.1500 x 379 | m. +91.982.324.7631 | > [email protected] | Learn more atnttdata.com/americas > > From: [email protected] [mailto:[email protected]] On > Behalf Of Michael Bayer > Sent: Friday, January 04, 2013 10:12 PM > To: [email protected] > Subject: Re: [sqlalchemy] Query about exception being raised on violating > uniqueness constraint > > Would need much more detail here including a full stack trace, what line > you're referring to in _flush(), and preferably code which reproduces the > error you're seeing. > > > On Jan 4, 2013, at 1:55 AM, Gurjar, Unmesh wrote: > > > Hi, > > I have installed SQLAlchemy 0.7.9 (backend – MySQL, Python 2.7). I have a > defined a table having a uniqueness constraint. On inserting a record which > violates this constraint, my application gets a ‘TypeError’ exception instead > of ‘IntegrityError’. > > After debugging the issue, I found that it can be resolved by replacing the > 'raise' statement by 'raise exc' in _flush( ) method of > sqlalchemy/orm/session.py. Can someone please confirm if this should be the > expected behavior? > > Thanks & Regards, > Unmesh Gurjar. > > > ______________________________________________________________________ > Disclaimer:This email and any attachments are sent in strictest confidence > for the sole use of the addressee and may contain legally privileged, > confidential, and proprietary data. If you are not the intended recipient, > please advise the sender by replying promptly to this email and then delete > and destroy this email and any attachments without any further use, copying > or forwarding > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > ______________________________________________________________________ > Disclaimer:This email and any attachments are sent in strictest confidence > for the sole use of the addressee and may contain legally privileged, > confidential, and proprietary data. If you are not the intended recipient, > please advise the sender by replying promptly to this email and then delete > and destroy this email and any attachments without any further use, copying > or forwarding > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > <integrity_error_test.py> -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
