From 39f6d5a5fdc01ccd05723f35b96d011100f7042f Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Mon, 3 Dec 2018 13:59:33 +0100 Subject: [PATCH] Py3: Fix two unbound variables In Python 3, the scope of errors in "try/except" clauses is more limited than in Python 2. Change-Id: I600145cd462b0f20740c290ecc4041fb4de02b33 --- swift/container/sharder.py | 5 +++-- test/unit/obj/test_expirer.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/swift/container/sharder.py b/swift/container/sharder.py index 34c8d82b06..998114d48f 100644 --- a/swift/container/sharder.py +++ b/swift/container/sharder.py @@ -1522,10 +1522,11 @@ class ContainerSharder(ContainerReplicator): self._increment_stat('visited', 'success', statsd=True) else: self._increment_stat('visited', 'skipped') - except (Exception, Timeout) as error: + except (Exception, Timeout) as err: self._increment_stat('visited', 'failure', statsd=True) self.logger.exception( - 'Unhandled exception while processing %s: %s', path, error) + 'Unhandled exception while processing %s: %s', path, err) + error = err try: self._record_sharding_progress(broker, node, error) except (Exception, Timeout) as error: diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index 8df8936234..0f312813db 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -744,10 +744,9 @@ class TestObjectExpirer(TestCase): x.run_once = raise_exceptions x.run_forever() except SystemExit as err: - pass + self.assertEqual(str(err), 'exiting exception 2') finally: expirer.sleep = orig_sleep - self.assertEqual(str(err), 'exiting exception 2') self.assertEqual(x.logger.get_lines_for_level('error'), ['Unhandled exception: ']) log_args, log_kwargs = x.logger.log_dict['error'][0]