Skip to content

Commit

Permalink
Bump minimum fsspec version to 2023.12.0 (#280)
Browse files Browse the repository at this point in the history
* Access error message safely, rework test assumptions

We were getting some bad accesses (key errors) on empty-body API responses
from the lakeFS server, causing a crash in the error handling.

* Bump minimum fsspec version to 2023.12.0

This means that the polymorphic filesystem facility, which was upstreamed
to fsspec and first appeared in that release, can go away.
  • Loading branch information
nicholasjng authored May 7, 2024
1 parent 4c4a32f commit b5a1f85
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classifiers = [
"Typing :: Typed",
]

dependencies = ["fsspec>=2023.6.0", "lakefs>=0.2.0"]
dependencies = ["fsspec>=2023.12.0", "lakefs>=0.2.0"]

dynamic = ["version"]

Expand Down
4 changes: 2 additions & 2 deletions src/lakefs_spec/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def translate_lakefs_error(

if hasattr(error, "body"):
# error has a JSON response body attached
reason = error.body["message"]
reason = error.body.get("message", "")
else:
reason = error.reason

emsg = f"{status} {reason}"
emsg = f"{status} {reason}".rstrip()
if rpath:
emsg += f": {rpath!r}"

Expand Down
20 changes: 1 addition & 19 deletions src/lakefs_spec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class LakeFSFileSystem(AbstractFileSystem):
"""

protocol = "lakefs"
transaction_type = LakeFSTransaction

def __init__(
self,
Expand Down Expand Up @@ -135,25 +136,6 @@ def _strip_protocol(cls, path):
return spath + "/"
return spath

@property
def transaction(self) -> LakeFSTransaction:
"""
A context manager within which file uploads and versioning operations are deferred to a
queue, and carried out during when exiting the context.
Requires the file class to implement ``.commit()`` and ``.discard()`` for the normal and exception cases.
"""
self._transaction: LakeFSTransaction | None
if self._transaction is None:
self._transaction = LakeFSTransaction(self)
return self._transaction

def start_transaction(self):
raise NotImplementedError(
"lakeFS transactions should only be used as a context manager via"
" `with LakeFSFileSystem.transaction as tx:`"
)

@contextmanager
def wrapped_api_call(
self, rpath: str | None = None, message: str | None = None, set_cause: bool = True
Expand Down
5 changes: 1 addition & 4 deletions src/lakefs_spec/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class LakeFSTransaction(Transaction):
The lakeFS file system associated with the transaction.
"""

def __init__(
self,
fs: "LakeFSFileSystem",
):
def __init__(self, fs: "LakeFSFileSystem"):
super().__init__(fs=fs)
self.fs: "LakeFSFileSystem"
self.files: deque[ObjectWriter] = deque(self.files)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_put_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_implicit_branch_creation(

fs.create_branch_ok = False
another_non_existing_branch = "non-existing-" + "".join(random.choices(string.digits, k=8))
with pytest.raises(FileNotFoundError, match="Not Found: .*"):
with pytest.raises(FileNotFoundError):
put_random_file_on_branch(random_file_factory, fs, repository, another_non_existing_branch)


Expand Down

0 comments on commit b5a1f85

Please sign in to comment.