Comment 12 for bug 1812913

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (stable/rocky)

Reviewed: https://review.opendev.org/679858
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=cb928c4b3ab7a4086b1a716dc9cea2809fbcf5fe
Submitter: Zuul
Branch: stable/rocky

commit cb928c4b3ab7a4086b1a716dc9cea2809fbcf5fe
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
    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
    (cherry picked from commit 42ce739a0841e39bd267cc2fd19be53447faac85)