]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix for bug 902175
authorBrad Hall <brad@nicira.com>
Mon, 12 Dec 2011 18:26:21 +0000 (18:26 +0000)
committerBrad Hall <brad@nicira.com>
Mon, 12 Dec 2011 18:27:35 +0000 (18:27 +0000)
We can't use merge if we're removing a field from the port object so use add
instead.  Also, pass the session to port_get so that we don't run into the
"this port is already bound to session x" error.

Change-Id: I54a8484c8f6429ad18fb0c5e088720d21fc16299

quantum/db/api.py

index d262f8acf18be4a94c50955f67be62c2a9d5bf17..03a5f49235fe794ef98c35a1993d504fd3fc92f6 100644 (file)
@@ -159,12 +159,13 @@ def port_list(net_id):
       all()
 
 
-def port_get(port_id, net_id):
+def port_get(port_id, net_id, session=None):
     # confirm network exists
     network_get(net_id)
-    session = get_session()
+    if not session:
+        session = get_session()
     try:
-        return  session.query(models.Port).\
+        return session.query(models.Port).\
           filter_by(uuid=port_id).\
           filter_by(network_id=net_id).\
           one()
@@ -222,9 +223,9 @@ def port_unset_attachment(port_id, net_id):
     network_get(net_id)
 
     session = get_session()
-    port = port_get(port_id, net_id)
+    port = port_get(port_id, net_id, session)
     port.interface_id = None
-    session.merge(port)
+    session.add(port)
     session.flush()