From ac8b949706b8d0eb0a83193e0187f63dd7ee3225 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Fri, 11 Jan 2013 07:01:25 +0400 Subject: Fix error in NovaBase.save() method There is a bug in sqlalchemy with eventlet that doesn't allows us to use session.flush() without explicit transaction. If somethings went wrong in DB and rollback is called it will try to raise NoneType. I found only one way to handle this situation. We should start transaction (or subtransaction if it already exists in session) explicitly. Fixes bug 1098692 Change-Id: I12cd643500e341a013cd7c963cb5d1a0106c7940 --- nova/db/sqlalchemy/models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 95fa6313f..52985a3eb 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -48,8 +48,17 @@ class NovaBase(object): """Save this object.""" if not session: session = get_session() - session.add(self) - session.flush() + # NOTE(boris-42): This part of code should be look like: + # sesssion.add(self) + # session.flush() + # But there is a bug in sqlalchemy and eventlet that + # raises NoneType exception if there is no running + # transaction and rollback is called. As long as + # sqlalchemy has this bug we have to create transaction + # explicity. + with session.begin(subtransactions=True): + session.add(self) + session.flush() def soft_delete(self, session=None): """Mark this object as deleted.""" -- cgit