Replace exception "re-raises" with excutils.save_and_reraise_exception()

Bug #1281453 reported by David Koo
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Glance
Triaged
Undecided
Unassigned
neutron
Invalid
Undecided
Lee Li

Bug Description

There are quite a few places in the Glance code where exceptions are re-raised:

  try:
     some_operation()
  except FooException as e:
    do_something1()
    raise
  except BarException as e:
    do_something2()
    raise

These places should use the excutils.save_and_reraise_exception class because in some cases the exception context can be cleared, resulting in None being attempted to be re-raised after an exception handler is run (see excutils.save_and_reraise_exception for more).

  try:
     some_operation()
  except FooException as e:
      with excutils.save_and_reraise_exception() as ctxt:
          do_something1()
  except BarException as e:
      with excutils.save_and_reraise_exception() as ctxt:
          do_something2()

Rohan (kanaderohan)
Changed in glance:
assignee: nobody → Rohan (kanaderohan)
Rohan (kanaderohan)
Changed in glance:
assignee: Rohan (kanaderohan) → nobody
Changed in glance:
assignee: nobody → Aswad Rangnekar (aswad-r)
Changed in glance:
assignee: Aswad Rangnekar (aswad-r) → nobody
Revision history for this message
Sam Stavinoha (smlstvnh) wrote :
Lee Li (lilinguo)
Changed in neutron:
assignee: nobody → Lee Li (lilinguo)
Jia Dong (jiadong-jia)
Changed in glance:
assignee: nobody → Jia Dong (jiadong-jia)
assignee: Jia Dong (jiadong-jia) → nobody
Revision history for this message
Mark McClain (markmcclain) wrote :

This has been covered by other work in Neutron.

Changed in neutron:
status: New → Invalid
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.openstack.org/78023
Committed: https://git.openstack.org/cgit/openstack/glance/commit/?id=eb40bb67601717558cc98e913b11d46547693d0b
Submitter: Jenkins
Branch: master

commit eb40bb67601717558cc98e913b11d46547693d0b
Author: Sam Stavinoha <email address hidden>
Date: Tue Mar 4 15:49:58 2014 -0600

    When re-raising exceptions, use save_and_reraise

    In some cases the exception context can be cleared,
    resulting in None being attempted to be re-raised after
    an exception handler is run.

    Change-Id: I16811ba8f0bfaa15199a648748bbc7d7a6a500bc
    Partial-Bug:#1281453

Changed in glance:
assignee: nobody → Roman Vasilets (rvasilets)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on glance (master)

Change abandoned by Roman Vasilets (<email address hidden>) on branch: master
Review: https://review.openstack.org/115948

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

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

Changed in glance:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on glance (master)

Change abandoned by Roman Vasilets (<email address hidden>) on branch: master
Review: https://review.openstack.org/116239

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Flavio Percoco (<email address hidden>) on branch: master
Review: https://review.openstack.org/116239
Reason: This patch hasn't been touched for a while and it seems to not be relevant anymore. I'm abandoning it for now. Feel free to restore it with an updated version if you think it's still relevant.

Changed in glance:
assignee: Roman Vasilets (rvasilets) → nobody
İrfan AKIN (irfan-akin)
Changed in glance:
assignee: nobody → İrfan AKIN (irfan-akin)
Revision history for this message
İrfan AKIN (irfan-akin) wrote :
Revision history for this message
İrfan AKIN (irfan-akin) wrote :
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on glance (master)

Change abandoned by ?rfan AKIN (<email address hidden>) on branch: master
Review: https://review.openstack.org/270702

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Nikhil Komawar (<email address hidden>) on branch: master
Review: https://review.openstack.org/263300
Reason: I see no movement on this patch. Please reopen as/when you find appropriate.

Revision history for this message
Brian Rosmaita (brian-rosmaita) wrote :

Resetting this bug in case some one else wants to pick it up. Looks like this is still happening in a few places:

[master] wha'ppen? grep -I -R -n --exclude-dir=tests --exclude-dir=registry --exclude-dir=v1 'raise$' glance/*
glance/api/policy.py:108: raise
glance/api/v2/image_data.py:143: raise
glance/cmd/cache_manage.py:72: raise
glance/common/exception.py:50: raise
glance/common/wsgi.py:414: raise
glance/common/wsgi.py:574: raise
glance/common/wsgi.py:683: raise
glance/common/utils.py:402: raise
glance/common/rpc.py:114: :param bool raise_exc: Specifies whether to raise
glance/common/rpc.py:202: raise
glance/db/sqlalchemy/metadef_api/resource_type.py:105: raise
glance/db/sqlalchemy/metadef_api/namespace.py:271: raise
glance/db/sqlalchemy/metadef_api/namespace.py:299: raise
glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py:61: raise
glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py:89: raise
glance/image_cache/drivers/xattr.py:472: raise
glance/image_cache/drivers/sqlite.py:87: raise
glance/scrubber.py:373: raise

Probably don't want to change the migration scripts, though.

Changed in glance:
assignee: İrfan AKIN (irfan-akin) → nobody
status: In Progress → Triaged
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Artem V. Okhotnikov (<email address hidden>) on branch: master
Review: https://review.opendev.org/667581

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.