In some cases, when loading a list of volumes using
cinder.objects.VolumeList.get_all we may end up with a SQL alchemy error
like this one:
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance
<VolumeAttachment at 0x7f048ff22290> is not bound to a Session; lazy
load operation of attribute 'volume' cannot proceed (Background on this
error at: http://sqlalche.me/e/bhk3)
This happens because when loading a Cinder Volume we also load the
volume attachments, so the Volume OVO tries to create the
VolumeAttachmentList OVO, which in turn creates the individual
VolumeAttachment OVOs, but these have the volume field set in
expected_attrs, but in this case the volume data is not loaded.
In most cases we don't see this issue because the session is still
available and SQLAlchemy will return this information.
Instead of using the dictionary "get" method that will do the lazy
loading we use the hasattr method that will return False if the lazy
loading exception happens when trying to get the volume.
Depends-On: I9f0fec25444ed865d56d0d250fb6d840ab5b4095
Closes-Bug: #1812913
Change-Id: I253123d5451b32f0e3143916e41aaa1af75561c2