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

Brandon Craig Rhodes brandon at rhodesmill.org
Fri Jul 18 11:36:48 EDT 2008


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?

-- 
Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon


More information about the Zope-Dev mailing list