From b0652c0dff90d68a6a7cf84b536e7e539e344f74 Mon Sep 17 00:00:00 2001 From: Brad Hall Date: Mon, 12 Dec 2011 18:26:21 +0000 Subject: [PATCH] Fix for bug 902175 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/quantum/db/api.py b/quantum/db/api.py index d262f8acf18..03a5f49235f 100644 --- a/quantum/db/api.py +++ b/quantum/db/api.py @@ -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()