On May 26, 2011, at 11:58 AM, Torsten Landschoff wrote:

> 
> How much more context would be helpful? Basically, this is the top of
> the backtrace. Above of that call is only the event handler hierarchy.
> 
>  File "/home/torsten/workspace/loco2-git/loco2/ui/wizard/importwizard.py", 
> line 69, in do_component_import
>    session.commit()

above is likely the offending line of code.   commit() should not be called if 
an exception has been raised within flush() - the Session is in a state whereby 
it is waiting for rollback() to be called.


> 
> I am actually using autocommit=True and autoflush=False. The reason is
> that autoflush=True caused a bunch of errors as I load hierarchical data
> in bottom up fashion and SQLAlchemy tried to flush objects to the
> database before a parent was available.
> 
> What's so bad about autocommit=True? I don't really remember why I ended
> up using it. It would probably suffice to replace most flush() calls
> with commit() and be done with it.

if you're using autocommit=True and you are not calling session.begin(), then 
session.commit() cannot be called in any case -there is no transaction present 
- it will raise an error directly:

from sqlalchemy.orm import Session

s = Session(autocommit=True)
s.commit()

output:

sqlalchemy.exc.InvalidRequestError: No transaction is begun.
  

autocommit=True is SQLAlchemy's original transaction behavior in the Session.  
It doesn't allow for the Session to have any context as to when it's safe to 
expire objects, and I can't currently think of any cases where it is truly 
needed for anything - it seems to be used either because it is misunderstood, 
as seems possibly the case here as it has nothing to do with autoflush, or 
because some users really don't want to have to figure out when their 
application should be saying "commit()", which IMHO is a serious architectural 
problem.   It is also used by legacy code and for some Zope extensions where 
they'd like to call Session.begin() explicitly in order to control scope better 
(and even there I'm not sure if they truly need it).

> 
> 
> BTW: The error is not reproducible anymore.
> 
> Greetings, Torsten
> 
> -- 
> DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
> Torsten Landschoff
> 
> Office Dresden
> Tel: +49-(0)351-4519587
> Fax: +49-(0)351-4519561
> 
> mailto:[email protected]
> http://www.dynamore.de
> 
> Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
> Managing director:  Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz
> 
> -- 
> 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.

Reply via email to