summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2013-01-11 07:01:25 +0400
committerBoris Pavlovic <boris@pavlovic.me>2013-01-12 00:57:14 +0400
commitac8b949706b8d0eb0a83193e0187f63dd7ee3225 (patch)
tree4e3a2e6a832ce4f26afab17d1439f9e62aec5f3c
parentb35f86651120c52e611e671caad331e4f871c2cc (diff)
downloadnova-ac8b949706b8d0eb0a83193e0187f63dd7ee3225.tar.gz
nova-ac8b949706b8d0eb0a83193e0187f63dd7ee3225.tar.xz
nova-ac8b949706b8d0eb0a83193e0187f63dd7ee3225.zip
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
-rw-r--r--nova/db/sqlalchemy/models.py13
1 files 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."""