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
This commit is contained in:
parent
926cbc18b5
commit
b0bb65d59c
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user