diff --git a/r2/r2/lib/stats.py b/r2/r2/lib/stats.py index e658baf92..eb802926c 100644 --- a/r2/r2/lib/stats.py +++ b/r2/r2/lib/stats.py @@ -85,7 +85,7 @@ class Stats: if self.connection: return self.statsd.timer.Timer(name, self.connection) else: - return None + return utils.SimpleSillyStub() def transact(self, action, service_time_sec): timer = self.get_timer('service_time') diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index f47f5b57f..fb61fead4 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -1310,6 +1310,17 @@ class Bomb(object): def __repr__(cls): raise Hell() +class SimpleSillyStub(object): + """A simple stub object that does nothing when you call its methods.""" + def __nonzero__(self): + return False + + def __getattr__(self, name): + return self.stub + + def stub(self, *args, **kwargs): + pass + def strordict_fullname(item, key='fullname'): """Sometimes we migrate AMQP queues from simple strings to pickled dictionaries. During the migratory period there may be items in