From b0bb65d59ca13159ccd9ef6b106e6cd5bb1cbfeb Mon Sep 17 00:00:00 2001 From: John Vrbanac Date: Sat, 7 Mar 2015 19:20:18 -0600 Subject: [PATCH] Fix for order obj expiration issue with SQLAlchemy By default, SQLAlchemy expires object state on commit. In some cases (usually testing), the new_order object expires causing the whole transaction to fail because SQLAlchemy raises an exception saying that the object isn't bound to a session. This is because we're trying to access the id attribute on a expired object. This patch pulls a copy of the order_id off before we commit to the db; which can expire the new_order object. Change-Id: I799f6a52c20304abb6e537f5cbe69926efe38ead --- barbican/api/controllers/orders.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/barbican/api/controllers/orders.py b/barbican/api/controllers/orders.py index 5b2e0f712..571914933 100644 --- a/barbican/api/controllers/orders.py +++ b/barbican/api/controllers/orders.py @@ -195,13 +195,17 @@ class OrdersController(object): new_order.project_id = project.id self.order_repo.create_from(new_order) + + # Grab our id before commit due to obj expiration from sqlalchemy + order_id = new_order.id + # Force commit to avoid async issues with the workers repo.commit() - self.queue.process_type_order(order_id=new_order.id, + self.queue.process_type_order(order_id=order_id, project_id=external_project_id) - url = hrefs.convert_order_to_href(new_order.id) + url = hrefs.convert_order_to_href(order_id) pecan.response.status = 202 pecan.response.headers['Location'] = url