Skip to content

Guard HSES tempdir cleanup when unzip was never called - #85

Open
arpitjain099 wants to merge 1 commit into
HHS:mainfrom
arpitjain099:chore/hses-tempdir-cleanup-guard
Open

Guard HSES tempdir cleanup when unzip was never called#85
arpitjain099 wants to merge 1 commit into
HHS:mainfrom
arpitjain099:chore/hses-tempdir-cleanup-guard

Conversation

@arpitjain099

Copy link
Copy Markdown

Small fix I hit while reading through the HSES client.

clean_up_tempdir() runs shutil.rmtree(self.__tempdir), but __tempdir is only set inside unzip(). If an HSES instance is created but never unzipped (for example get_data() raising before unzip() runs), the attribute is unset and clean_up_tempdir() raises AttributeError: '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 __tempdir to None and 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant