See:
http://www.sqlalchemy.org/docs/05/reference/orm/sessions.html#sqlalchemy.orm.create_session
“The defaults of create_session() are the opposite of that of
sessionmaker(); autoflush and expire_on_commit are False, autocommit is
True. [...] It is recommended to use sessionmaker() instead of
create_session().”
Isn't that it?
- G.
On Wed, Mar 4, 2009 at 7:21 PM, Mike Orr <[email protected]> wrote:
>
> I have a standalone utility using a model based on Declarative on
> MySQL using SQLAlchemy 0.5.2. Most of the code is at the SQL level
> but at one point I use the ORM to update or insert a summary record.
> So I figured I'd use create_session because it's a single-threaded
> utility.
>
> ===
> sess = orm.create_session(bind=conn)
> q = sess.query(model.Monthly).filter_by(...)
> monthly = q.first()
> if not monthly:
> monthly = model.Monthly()
> ...
> sess.add(monthly)
> ...
> sess.commit()
> ===
>
> That raises "sqlalchemy.exc.InvalidRequestError: No transaction is
> begun." To work around that I have to put "sess.begin()" after
> creating the session. But why? I don't have to do this when using
> scoped_session in Pylons. The SQLAlchemy docs seem to say that it
> automatically manages transactions if you don't change the default
> session arguments, and that this works identically with Session,
> create_session, and sessionmaker. So why is it behaving differently
> here?
>
> --
> Mike Orr <[email protected]>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---