Fix when source is none

AttributeError: 'NoneType' object has no attribute 'hasattr'