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
(cherry picked from commit 1a8a15f630)