-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Use context managers for opening zipfiles #3369
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, glad to see it's so straightforward :) There are a few other places where we use get_zipfile_resource
outside of a context manager (dbf.py
, eia176.py
, epacems.py
, etl_test.py
, glue_assets.py
) - any particular reason not to change those as well?
Ugh I goofed this rebase. @jdangerx any idea how to resolve it? I only meant to push the latest commit. |
I went back and added context managers to where we use Lines 340 to 350 in 3630dca
It doesn't seem right to pass an open I'm also more optimistic adding context managers will resolve the
This makes me think the "essential records" weren't written and the PHMSA and FERC 714 extractors tried to reopen these corrupted zipfiles. However, I don't know what "essential records" would need to be written when you are reading the file 🤷 |
Leaving the Your comment about essential records led me down this rabbit hole: https://github.com/python/cpython/blob/3.12/Lib/zipfile/__init__.py#L1211 |
3630dca
to
051faba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤐
Overview
Hopefully, using context managers to close connections to zip files will resolve our sporadic
BadZipFile
error #3364.Testing
How did you make sure this worked? How can a reviewer verify this?
To-do list