[Zope-dev] Re: could zope.sqlalchemy flush before committing?

Laurence Rowe l at lrowe.co.uk
Fri Jul 18 16:34:43 EDT 2008


This is now fixed in trunk. For the moment I'm depending on SQLAlchemy 
trunk for the new after_attach hook until beta3 is released.

Maybe it's time to start depending on 0.5?

Laurence

Brandon Craig Rhodes wrote:
> I complained recently about problems with things disappearing from an
> in-memory sqlite database.  It appears that my problems were actually
> symptoms of something else: that, so far as I can see, doing a
> 
>    transaction.commit()
> 
> when SQLAlchemy is active does *not* first do a session().commit()!
> This means that the following sequence in a test suite:
> 
>    >>> p = Person(name='Brandon')
>    >>> s = session()
>    >>> s.add(p)
>    >>> transaction.commit()
> 
>    >>> s.attribute = 'an illegal value'
>    Traceback:
>       ...
>    Exception: the database does not allow that attribute to have that value
>    >>> transaction.rollback()
> 
> Instead, to make this work, one has to write the first stanza as:
> 
>    >>> p = Person(name='Brandon')
>    >>> s = session()
>    >>> s.add(p)
>    >>> s.flush()  # Sheesh
>    >>> transaction.commit()
> 
> Could zope.sqlalchemy be improved so that, on transaction commit, the
> current SQLAlchemy session is first flushed before being committed?
> 



More information about the Zope-Dev mailing list