Skip to content

fix: raise UnsupportedOperation exception in fsspec.BufferedFile impl - #769

Open
RacleRay wants to merge 1 commit into
developmentseed:mainfrom
RacleRay:fix_fsspec_zip_failback
Open

fix: raise UnsupportedOperation exception in fsspec.BufferedFile impl#769
RacleRay wants to merge 1 commit into
developmentseed:mainfrom
RacleRay:fix_fsspec_zip_failback

Conversation

@RacleRay

Copy link
Copy Markdown
  • zipfile.ZipFile.init only catch OSError
  • io.UnsupportedOperation inherits OSError and ValueError, may be helpful

@ds-release-bot ds-release-bot Bot added the fix label Aug 19, 2026
@kylebarron

Copy link
Copy Markdown
Member

Can you provide some rationale for this change? Is this something that fsspec expects?

@RacleRay

RacleRay commented Aug 21, 2026

Copy link
Copy Markdown
Author

Yes, the rationale:

Problem: A file opened via obstore-fsspec crashes zipfile.ZipFile in write mode:

from obstore.fsspec import register
register("s3")

fs = fsspec.filesystem("s3", config=config)

with fs.open(url) as filelike, zipfile.ZipFile(filelike, "w") as zf:  # ValueError raised here
    ...

Root cause: our tell() raises a bare ValueError on non-seekable files, but ZipFile.init only catches (AttributeError, OSError) when probing fp.tell(), so the _Tellable fallback never kicks in (CPython 3.12, zipfile init.py:1352–1391):

try:
    self.start_dir = self.fp.tell()
except (AttributeError, OSError):  # ValueError is NOT caught here
    self.fp = _Tellable(self.fp)
    self.start_dir = 0
    self._seekable = False

Fix: io.UnsupportedOperation inherits from both OSError and ValueError

Thanks for your reply.

@kylebarron

Copy link
Copy Markdown
Member

Ok, could you add a test case to this PR that previously errored and now works?

@RacleRay
RacleRay force-pushed the fix_fsspec_zip_failback branch from cc7ed3c to b6e7f6c Compare August 23, 2026 16:56
- zipfile.ZipFile.__init__ only catch `OSError`
- io.UnsupportedOperation inherits `OSError` and `ValueError`, may be helpful
- add a test simple test at tests/test_fsspec.py
@RacleRay
RacleRay force-pushed the fix_fsspec_zip_failback branch from b6e7f6c to 505c8bc Compare August 23, 2026 17:02
@RacleRay

Copy link
Copy Markdown
Author

Done, added test_zipfile_write_mode in tests/test_fsspec.py. It reproduces the original scenario that wrapping a write-mode file with zipfile.ZipFile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants