Reviewed: https://review.openstack.org/568390 Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=1a8a15f6309a56087702a0974041fa9850de4f62 Submitter: Zuul Branch: master
commit 1a8a15f6309a56087702a0974041fa9850de4f62 Author: Ihar Hrachyshka <[email protected]> Date: Mon May 14 21:57:52 2018 +0000 objects: avoid deepcopying models in test_db_obj SQLAlchemy may asynchronously push models out of session cache in which case we may receive DetachedInstanceError. In the test case, instead of deepcopying models to compare, compare each modified attribute independently. This change also includes conversion from InstrumentedLists to regular lists when converting model attributes to object fields. The fact that we were returning InstrumentedLists was always an oversight but it revealed itself after the modification of the test case that is the core of this patch. When converting object fields to db, convert Port's distributed_binding None value to a empty list to reflect that the relationship of the Port database model is a list. It was not an issue before the patch because we were not comparing model attribute for equality but for in-equality before, and so None was always != []. Finally, this patch moves a bunch of TODOs to better reflect where they belong to. Closes-Bug: #1770452 Change-Id: I42cdf540129bd4470ec1a59345db9845a6198328 ** Changed in: neutron Status: In Progress => Fix Released -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to neutron. https://bugs.launchpad.net/bugs/1770452 Title: neutron.tests.unit.objects.test_subnet.SubnetDbObjectTestCase.test_db_obj failing with <NetworkSegment at 0x7fdf760a7310> is not bound to a Session Status in neutron: Fix Released Bug description: Today I found the same failure in two unrelated patches: http://logs.openstack.org/61/567461/1/check/openstack-tox-py27/1bbd80a /job-output.txt.gz#_2018-05-10_03_52_48_299412 http://logs.openstack.org/73/566673/2/gate/openstack-tox-cover/a8914e0 /job-output.txt.gz#_2018-05-10_12_42_13_309505 The traceback looks as follows: 2018-05-10 12:42:13.309505 | ubuntu-xenial | FAIL: neutron.tests.unit.objects.test_subnet.SubnetDbObjectTestCase.test_db_obj 2018-05-10 12:42:13.309555 | ubuntu-xenial | tags: worker-1 2018-05-10 12:42:13.309605 | ubuntu-xenial | ---------------------------------------------------------------------- 2018-05-10 12:42:13.309632 | ubuntu-xenial | Traceback (most recent call last): 2018-05-10 12:42:13.309666 | ubuntu-xenial | File "neutron/tests/base.py", line 140, in func 2018-05-10 12:42:13.309692 | ubuntu-xenial | return f(self, *args, **kwargs) 2018-05-10 12:42:13.309739 | ubuntu-xenial | File "neutron/tests/unit/objects/test_base.py", line 2017, in test_db_obj 2018-05-10 12:42:13.309768 | ubuntu-xenial | old_model = copy.deepcopy(obj.db_obj) 2018-05-10 12:42:13.309806 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 190, in deepcopy 2018-05-10 12:42:13.309833 | ubuntu-xenial | y = _reconstruct(x, rv, 1, memo) 2018-05-10 12:42:13.309897 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct 2018-05-10 12:42:13.309928 | ubuntu-xenial | state = deepcopy(state, memo) 2018-05-10 12:42:13.309967 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 163, in deepcopy 2018-05-10 12:42:13.310010 | ubuntu-xenial | y = copier(x, memo) 2018-05-10 12:42:13.310066 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict 2018-05-10 12:42:13.310141 | ubuntu-xenial | y[deepcopy(key, memo)] = deepcopy(value, memo) 2018-05-10 12:42:13.310187 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 190, in deepcopy 2018-05-10 12:42:13.310214 | ubuntu-xenial | y = _reconstruct(x, rv, 1, memo) 2018-05-10 12:42:13.310255 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct 2018-05-10 12:42:13.310280 | ubuntu-xenial | state = deepcopy(state, memo) 2018-05-10 12:42:13.310318 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 163, in deepcopy 2018-05-10 12:42:13.310338 | ubuntu-xenial | y = copier(x, memo) 2018-05-10 12:42:13.310380 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict 2018-05-10 12:42:13.310414 | ubuntu-xenial | y[deepcopy(key, memo)] = deepcopy(value, memo) 2018-05-10 12:42:13.310452 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 190, in deepcopy 2018-05-10 12:42:13.310479 | ubuntu-xenial | y = _reconstruct(x, rv, 1, memo) 2018-05-10 12:42:13.310519 | ubuntu-xenial | File "/usr/lib/python2.7/copy.py", line 352, in _reconstruct 2018-05-10 12:42:13.310538 | ubuntu-xenial | y.append(item) 2018-05-10 12:50:00.920204 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/collections.py", line 1044, in append 2018-05-10 12:50:00.920385 | ubuntu-xenial | item = __set(self, item, _sa_initiator) 2018-05-10 12:50:00.920620 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/collections.py", line 1016, in __set 2018-05-10 12:50:00.920754 | ubuntu-xenial | item = executor.fire_append_event(item, _sa_initiator) 2018-05-10 12:50:00.920975 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/collections.py", line 680, in fire_append_event 2018-05-10 12:50:00.921021 | ubuntu-xenial | item, initiator) 2018-05-10 12:50:00.921251 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 943, in fire_append_event 2018-05-10 12:50:00.921335 | ubuntu-xenial | state, value, initiator or self._append_token) 2018-05-10 12:50:00.921566 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 1228, in emit_backref_from_collection_append_event 2018-05-10 12:50:00.921628 | ubuntu-xenial | passive=PASSIVE_NO_FETCH) 2018-05-10 12:50:00.921845 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 624, in append 2018-05-10 12:50:00.921964 | ubuntu-xenial | self.set(state, dict_, value, initiator, passive=passive) 2018-05-10 12:50:00.922173 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 798, in set 2018-05-10 12:50:00.922227 | ubuntu-xenial | LOAD_AGAINST_COMMITTED) 2018-05-10 12:50:00.922414 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 599, in get 2018-05-10 12:50:00.922479 | ubuntu-xenial | value = self.callable_(state, passive) 2018-05-10 12:50:00.922680 | ubuntu-xenial | File "/home/zuul/src/git.openstack.org/openstack/neutron/.tox/cover/local/lib/python2.7/site-packages/sqlalchemy/orm/strategies.py", line 596, in _load_for_state 2018-05-10 12:50:00.922743 | ubuntu-xenial | (orm_util.state_str(state), self.key) 2018-05-10 12:50:00.923061 | ubuntu-xenial | sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <NetworkSegment at 0x7fdf760a7310> is not bound to a Session; lazy load operation of attribute 'network' cannot proceed (Background on this error at: http://sqlalche.me/e/bhk3) To manage notifications about this bug go to: https://bugs.launchpad.net/neutron/+bug/1770452/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : [email protected] Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp

