Hello Michael,

Thanks for your enlightening comments, pls see my comments below.

On 12/29/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> the transaction "commit" inside the create_draft method is a little
> strange.  usually, if you have a long running transaction, there would
> be a begin()/commit() pair framing a series of operations.  issuing
> commits inside of method sets seems to imply you dont really want a
> "transactional" session....but the session begins the next transaction
> lazily so theres probably nothing terrible about doing it that way.


Got it, I think. I get rid of all .commit() calls and wrap all methods with
explicit transactions:


    @transactional_method()
    def create_draft(self):
         # ...

def transactional_method():
    def wrapper(func, self, *args, **kwargs):
        session = self.session # shortcut
        session.begin()
        try:
            rv = func(self, *args, **kwargs)
            session.commit()
            return rv
        except:
            session.rollback()
            raise
    return decorator(wrapper)

I also turn off automatic transactions:
Session = scoped_session(sessionmaker(autoflush=True, transactional=False))

Does it looks correct? It works, as far as my tests tell me.

I've tried transactional=True but it broke the app in a lot of places where
there were no explicit commits. May be I update the code eventually to
always be explicit but for now I'm more concerned to get the code working
again, after 0.4 update.


> Btw, is it possible to retrieve metadata if you have an engine or
> > configured session object? I haven't found a way so ended up storing
> > it in a module global when session is configured.
>
> MetaData is usually a module global, its attached to tables also....so
> for example class_mapper(AnyMappedClass).mapped_table.metadata


This method works for me, thanks.

Max.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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