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

fix httpfile serialization bug #973

Merged
merged 2 commits into from
May 30, 2022

Conversation

rabernat
Copy link
Contributor

This implements the suggestion in pangeo-forge/pangeo-forge-recipes#370 (comment), which fixes a bug in how HTTPFile is serialized.

It's a bit worrying to me that serialization of HTTPFile is not covered by tests sufficiently to have already surfaced this bug. Therefore, I would like to use this PR to contribute some improvements to testing as well.

@martindurant
Copy link
Member

I think this PR is fine, and solves one arm of he possibilities in #579 .

Another possible thing to consider, is making OpenFile file-like, calling into .open() when required. Seems like a rather large change to the core API.

@martindurant martindurant merged commit 06c4003 into fsspec:master May 30, 2022
@@ -350,7 +350,7 @@ def __getattr__(self, item):

def __enter__(self):
self._incontext = True
return self.f.__enter__()
return self
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in assuming that this will solve

open_file = fsspec.open(local_path) -> <OpenFile '/local/path.nc'>
❌ doesn't work with context manager (TypeError: cannot pickle '_io.BufferedReader' object)

from #579 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the

with fsspec.open(localpath) as f:

case. I think that's what you said.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: just re-ran my test and the answer is YES! ✅

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.

2 participants