Guard HSES tempdir cleanup when unzip was never called - #85
Open
arpitjain099 wants to merge 1 commit into
Open
Conversation
clean_up_tempdir() calls shutil.rmtree(self.__tempdir), but __tempdir is only assigned in unzip(). On an HSES instance that is constructed but never unzipped (for example when get_data() raises before unzip), the attribute is unset, so clean_up_tempdir() raises AttributeError. Because __del__ calls clean_up_tempdir(), the same error also surfaces as an 'Exception ignored in __del__' traceback on garbage collection. Initialize __tempdir to None and skip removal when there is nothing to clean up, which also makes the method idempotent. Adds a regression test. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Small fix I hit while reading through the HSES client.
clean_up_tempdir()runsshutil.rmtree(self.__tempdir), but__tempdiris only set insideunzip(). If an HSES instance is created but never unzipped (for exampleget_data()raising beforeunzip()runs), the attribute is unset andclean_up_tempdir()raisesAttributeError: 'HSES' object has no attribute '_HSES__tempdir'. Since__del__calls the same method, it also shows up as an "Exception ignored in del" traceback when the object is garbage collected.The change initializes
__tempdirtoNoneand skips removal when there is nothing to clean up, which also makes the method idempotent (a second call is a no-op). The happy path still removes a real tempdir.Added a regression test under tests/hses that constructs an HSES and calls
clean_up_tempdir()without unzipping. It fails on main with the AttributeError and passes with this change. Ran it locally on Python 3.12.Thanks for maintaining this.