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.
Reviewed: https:/ /review. opendev. org/679858 /git.openstack. org/cgit/ openstack/ cinder/ commit/ ?id=cb928c4b3ab 7a4086b1a716dc9 cea2809fbcf5fe
Committed: https:/
Submitter: Zuul
Branch: stable/rocky
commit cb928c4b3ab7a40 86b1a716dc9cea2 809fbcf5fe
Author: Gorka Eguileor <email address hidden>
Date: Tue Jan 22 21:24:37 2019 +0100
Fix VolumeAttachment is not bound to a Session
In some cases, when loading a list of volumes using objects. VolumeList. get_all we may end up with a SQL alchemy error
cinder.
like this one:
sqlalchemy .orm.exc. DetachedInstanc eError: Parent instance achment at 0x7f048ff22290> is not bound to a Session; lazy sqlalche. me/e/bhk3)
<VolumeAtt
load operation of attribute 'volume' cannot proceed (Background on this
error at: http://
This happens because when loading a Cinder Volume we also load the hmentList OVO, which in turn creates the individual hment OVOs, but these have the volume field set in
volume attachments, so the Volume OVO tries to create the
VolumeAttac
VolumeAttac
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: I9f0fec25444ed8 65d56d0d250fb6d 840ab5b4095 f0e3143916e41aa a1af75561c2 bd267cc2fd19be5 3447faac85)
Closes-Bug: #1812913
Change-Id: I253123d5451b32
(cherry picked from commit 42ce739a0841e39