Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructor of LocalTarget sometimes fails with AttributeError: 'LocalTarget' object has no attribute 'is_tmp' #3085

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion luigi/local_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def fn(self):
return self.path

def __del__(self):
if self.is_tmp and self.exists():
if hasattr(self, "is_tmp") and self.is_tmp and self.exists():
self.remove()
10 changes: 10 additions & 0 deletions test/local_target_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,13 @@ def test_move_to_new_dir(self):
LocalTarget(src).open('w').close()
self.fs.move(src, dest)
self.assertTrue(os.path.exists(dest))


class DestructorTest(unittest.TestCase):

def test_destructor(self):
# LocalTarget might not be fully initialised if an exception is thrown in the constructor of LocalTarget or a
# subclass. The destructor can't expect attributes to be initialised.
t = LocalTarget(is_tmp=True)
del t.is_tmp
t.__del__()