Cannot save a RequestSpec object if nothing changed

Bug #1775863 reported by Balazs Gibizer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Balazs Gibizer

Bug Description

If a RequestSpec.save() is called on an object that has no changed field the code blows up with UnboundLocalError:

      File "nova/tests/unit/objects/test_request_spec.py", line 622, in test_save_does_not_persist_requested_resources
        req_obj.save()
      File "/mnt/ssd/ebalgib/nova/py27/.tox/py27/local/lib/python2.7/site-packages/oslo_versionedobjects/base.py", line 226, in wrapper
        return fn(self, *args, **kwargs)
      File "nova/objects/request_spec.py", line 588, in save
        updates = self._get_update_primitives()
      File "nova/objects/request_spec.py", line 561, in _get_update_primitives
        return db_updates
    UnboundLocalError: local variable 'db_updates' referenced before assignment

It is because the db_updates local is only initialized if there is something to update but returned regardless
https://github.com/openstack/nova/blob/master/nova/objects/request_spec.py#L518
https://github.com/openstack/nova/blob/master/nova/objects/request_spec.py#L532

Changed in nova:
assignee: nobody → Balazs Gibizer (balazs-gibizer)
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/573768

Changed in nova:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/573768
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=08fb09e878dcaedbb446e18502a6172fa4d43121
Submitter: Zuul
Branch: master

commit 08fb09e878dcaedbb446e18502a6172fa4d43121
Author: Balazs Gibizer <email address hidden>
Date: Fri Jun 8 17:57:07 2018 +0200

    Fix unbound local when saving an unchanged RequestSpec

    RequestSpec._get_update_primitives() tried to return the unitialized
    db_updates field when the object has no changes. This patch initalizes
    that local to None and handles that None in create() and save() where
    the RequestSpec._get_update_primitives() is called.

    Change-Id: Iad256079945bf8b5745ebdcc393c55115dbcab75
    Closes-Bug: #1775863

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.openstack.org/580309

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

Reviewed: https://review.openstack.org/580309
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=a31ebd87ba9a9c0ab0013fe59b6d5056c1193f4c
Submitter: Zuul
Branch: stable/queens

commit a31ebd87ba9a9c0ab0013fe59b6d5056c1193f4c
Author: Balazs Gibizer <email address hidden>
Date: Fri Jun 8 17:57:07 2018 +0200

    Fix unbound local when saving an unchanged RequestSpec

    RequestSpec._get_update_primitives() tried to return the unitialized
    db_updates field when the object has no changes. This patch initalizes
    that local to None and handles that None in create() and save() where
    the RequestSpec._get_update_primitives() is called.

    Change-Id: Iad256079945bf8b5745ebdcc393c55115dbcab75
    Closes-Bug: #1775863
    (cherry picked from commit 08fb09e878dcaedbb446e18502a6172fa4d43121)

tags: added: in-stable-queens
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/pike)

Fix proposed to branch: stable/pike
Review: https://review.openstack.org/580951

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 18.0.0.0b3

This issue was fixed in the openstack/nova 18.0.0.0b3 development milestone.

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

Reviewed: https://review.openstack.org/580951
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=6d60c74191f271c1fcea2ff1556a1f00baaa3f58
Submitter: Zuul
Branch: stable/pike

commit 6d60c74191f271c1fcea2ff1556a1f00baaa3f58
Author: Balazs Gibizer <email address hidden>
Date: Fri Jun 8 17:57:07 2018 +0200

    Fix unbound local when saving an unchanged RequestSpec

    RequestSpec._get_update_primitives() tried to return the unitialized
    db_updates field when the object has no changes. This patch initalizes
    that local to None and handles that None in create() and save() where
    the RequestSpec._get_update_primitives() is called.

    Change-Id: Iad256079945bf8b5745ebdcc393c55115dbcab75
    Closes-Bug: #1775863
    (cherry picked from commit 08fb09e878dcaedbb446e18502a6172fa4d43121)
    (cherry picked from commit a31ebd87ba9a9c0ab0013fe59b6d5056c1193f4c)

tags: added: in-stable-pike
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 16.1.5

This issue was fixed in the openstack/nova 16.1.5 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.6

This issue was fixed in the openstack/nova 17.0.6 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.