From 41194b797578db3235d803cc9c06d7570159c7ce Mon Sep 17 00:00:00 2001 From: Dave Berenbaum Date: Wed, 19 Jul 2023 13:54:55 -0400 Subject: [PATCH] dvcfs: handle NotADirectoryError from datafs.ls (#9746) * dvc_fs: ignore NotADirectoryError in ls * deps: bump dvc-data to >= 2.6.0 * add test --------- Co-authored-by: Ruslan Kuprieiev --- dvc/fs/dvc.py | 2 +- pyproject.toml | 2 +- tests/unit/fs/test_dvc.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dvc/fs/dvc.py b/dvc/fs/dvc.py index 4ba009928c..8c59c3b3aa 100644 --- a/dvc/fs/dvc.py +++ b/dvc/fs/dvc.py @@ -288,7 +288,7 @@ def ls( # pylint: disable=arguments-differ # noqa: C901 dvc_infos = {} if dvc_fs: dvc_path = _get_dvc_path(dvc_fs, subkey) - with suppress(FileNotFoundError): + with suppress(FileNotFoundError, NotADirectoryError): for info in dvc_fs.ls(dvc_path, detail=True): dvc_infos[dvc_fs.path.name(info["name"])] = info dvc_exists = bool(dvc_infos) or dvc_fs.exists(dvc_path) diff --git a/pyproject.toml b/pyproject.toml index 00b5bed02a..184b980dc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "configobj>=5.0.6", "distro>=1.3", "dpath<3,>=2.1.0", - "dvc-data>=2.5.0,<2.6.0", + "dvc-data>=2.6.0,<2.7.0", "dvc-http>=2.29.0", "dvc-render>=0.3.1,<1", "dvc-studio-client>=0.9.2,<1", diff --git a/tests/unit/fs/test_dvc.py b/tests/unit/fs/test_dvc.py index 2a6580f4f9..08cc4868c1 100644 --- a/tests/unit/fs/test_dvc.py +++ b/tests/unit/fs/test_dvc.py @@ -162,6 +162,16 @@ def test_isdir_mixed(tmp_dir, dvc): assert not fs.isfile("dir") +def test_ls_dirty(tmp_dir, dvc): + tmp_dir.dvc_gen({"data": "data"}) + (tmp_dir / "data").unlink() + + tmp_dir.gen({"data": {"foo": "foo", "bar": "bar"}}) + + fs = DVCFileSystem(repo=dvc) + assert set(fs.ls("data")) == {"data/foo", "data/bar"} + + @pytest.mark.parametrize( "dvcfiles,extra_expected", [