diff --git a/pytorch_lightning/root_module/decorators.py b/pytorch_lightning/root_module/decorators.py index ef7bd50283..f295be0cb0 100644 --- a/pytorch_lightning/root_module/decorators.py +++ b/pytorch_lightning/root_module/decorators.py @@ -10,8 +10,15 @@ def data_loader(fn): @property def _data_loader(self): - if not hasattr(self, attr_name): - setattr(self, attr_name, fn(self)) - return getattr(self, attr_name) + try: + value = getattr(self, attr_name) + except AttributeError: + try: + value = fn(self) # Lazy evaluation, done only once. + except AttributeError as e: + # Guard against AttributeError suppression. (Issue #142) + raise RuntimeError('An AttributeError was encountered: ' + str(e)) from e + setattr(self, attr_name, value) # Memoize evaluation. + return value return _data_loader